php 文件上传缩略图路径分析类

<?php

//文件上传时分析路径信息

//author:songzhenghe 2014-1-24

//version 0.1

class path_ana {

    private $data_root;

    private $web_root;

    private $http_domain;

    private $file;

    private $r;

    

    public function __construct(){

        //从配置文件中读取

        $this->data_root=‘E:/wwwroot2/cms/common/upload/‘;

        $this->web_root =‘E:/wwwroot2/cms/‘;

        $this->http_domain=http://www.cms.com/;

        $this->r=null;

    }

    //$file E:/wwwroot2/cms/common/upload/2013/08/345349534.jpg

    public function init($file){

        $this->file=$file;

        $return=array();

        

        $pathinfo=pathinfo($file);

        // E:/wwwroot2/cms/common/upload/2013/08/

        $return[0]=$pathinfo[‘dirname‘].‘/‘;

        // 345349534.jpg

        $return[1]=$pathinfo[‘basename‘];

        // 345349534

        if(strrpos($return[1],‘.‘)!==false){

            $return[2]=substr($return[1],0,strrpos($return[1],‘.‘));

        }else{

            $return[2]=$return[1];

        }

        // jpg

        $return[3]=$pathinfo[‘extension‘];

        // 2013/08/345349534.jpg

        $return[4]=$this->str_replace_once($this->data_root,‘‘,$file);

        // 2013/08/

        $return[5]=dirname($return[4]).‘/‘;

        // E:/wwwroot2/cms/common/upload/

        $return[6]=$this->data_root;

        // common/upload/2013/08/345349534.jpg

        $return[7]=$this->str_replace_once($this->web_root,‘‘,$file);

        // common/upload/2013/08/

        $return[8]=dirname($return[7]).‘/‘;

        // E:/wwwroot2/cms/

        $return[9]=$this->web_root;

        // common/upload/

        $return[10]=preg_replace(‘/‘.preg_quote($return[5],‘/‘).‘$/i‘,‘‘,$return[8],1);

        // http://www.cms.com/common/upload/2013/08/345349534.jpg

        $return[11]=$this->http_domain.$return[7];

        // /common/upload/2013/08/345349534.jpg

        $return[12]=‘/‘.$return[7];

        //  E:/wwwroot2/cms/common/upload/2013/08/345349534.jpg

        $return[13]=$this->file;

        

        $this->r=$return;

        return $return;

    }

    //http://www.php100.com/html/php/hanshu/2013/0905/4683.html

    private function str_replace_once($needle,$replace,$haystack) {

        $pos=strpos($haystack,$needle);

        if ($pos===false) return $haystack;

        return substr_replace($haystack,$replace,$pos,strlen($needle));

    }

    //

    public function rename_file($prefix=‘thumb_‘,$suffix=‘‘){

        if($this->r[3]){

            $new=$this->r[0].$prefix.$this->r[2].$suffix.‘.‘.$this->r[3];

        }else{

            $new=$this->r[0].$prefix.$this->r[2].$suffix;

        }

        return $new;

    }

    

//

}

echo ‘<pre>‘;

$file=‘E:/wwwroot2/cms/common/upload/2013/08/345349534.jpg‘;

$path_ana=new path_ana();

$r=$path_ana->init($file);

print_r($r);

$file=$path_ana->rename_file();

$r=$path_ana->init($file);

print_r($r);

Array
(
    [0] => E:/wwwroot2/cms/common/upload/2013/08/
    [1] => 345349534.jpg
    [2] => 345349534
    [3] => jpg
    [4] => 2013/08/345349534.jpg
    [5] => 2013/08/
    [6] => E:/wwwroot2/cms/common/upload/
    [7] => common/upload/2013/08/345349534.jpg
    [8] => common/upload/2013/08/
    [9] => E:/wwwroot2/cms/
    [10] => common/upload/
    [11] => http://www.cms.com/common/upload/2013/08/345349534.jpg
    [12] => /common/upload/2013/08/345349534.jpg
    [13] => E:/wwwroot2/cms/common/upload/2013/08/345349534.jpg
)
时间: 2024-08-06 20:06:07

php 文件上传缩略图路径分析类的相关文章

验证码确保php无输出、sql语句的封装性、文件上传的工具类【这三个重点工具类实现】

1.php代码在引入中不会进行结束或者确保结束之后没有空格,来保证php在被包含中没有被输出[防止header和session_start()对输出的控制]实质上,需要注意的就是,要不就进行输出缓存控制以及php开始标签前没有空格 验证码这个功能需要header和session两个功能[尤其需要注意输出的问题] [总结:防止php代码中带着一些输出的问题](1)在php标签中开始<?php 前顶格(2)php结束符要不不写,写了就不要在结束之后还有换行[防止该文件被包含之后提前出线输出](3)或

文件上传的Serlvet类

public class FileUploadServlet extends HttpServlet {  private static final long serialVersionUID = 1L;  private ServletFileUpload upload;  private final long MAXSize = 4194304*2L;//4*2MB  private String filedir=null;             /**      * @see HttpS

android 网络文件上传下载工具类总结

1.获取文件的最后修改时间 @SuppressLint("SimpleDateFormat") public String getFileDataTime(File file) { Date date = new Date(file.lastModified()); SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 24小时制 String LgTime = sdfo

iOS开发 - 封装文件上传工具类

文件上传的步骤 1.设置请求头 * 目的:告诉服务器请求体里面的内容并非普通的参数,而是包含了文件参数 [request setValue:@"multipart/form-data; boundary=maljob" forHTTPHeaderField:@"Content-Type"]; 2.设置请求体 * 作用:存放参数(文件参数和非文件参数) 1> 非文件参数 [body appendData:MalJobEncode(@"--maljob\

云控后台系统 经验总结(表单和文件上传等)

1. qq emoji替换 接收到这样的字符串,通过正则匹配到每组方括号然后进行替换 var _str = i.content.replace(/\[.{1,3}\]/g, (str) => { //i.content为遍历出来的消息记录 var index; Object.keys(faceCode).forEach((key, _index) => { //faceCode为字符串与样式对应的关系,也可以通过参数去和后台约定好,不用这样查找 if (key === str) { index

JavaWeb文件上传下载,使用fileupload组件

一.引入jar包 1. commons-fileupload-1.2.1.jar 2. commons-io-1.4.jar 二.文件上传 1. html代码 1 <form name="upload_test" action="${pageContext.request.contextPath}/FileServlet?method=upload" method="post" enctype="multipart/form-da

JavaWeb 后端 &lt;十四&gt; 文件上传下载

1.文件上传与下载 案例: 注册表单/保存商品等相关模块! --à 注册选择头像 / 商品图片 (数据库:存储图片路径 / 图片保存到服务器中指定的目录) 1.1 文件上传 文件上传,要点: 前台: 1. 提交方式:post 2. 表单中有文件上传的表单项: <input type=”file” /> 3. 指定表单类型: 默认类型:enctype="application/x-www-form-urlencoded" 文件上传类型:enctype =”multipart/

java文件上传-使用apache-fileupload组件

目前文件上传的(框架)组件:Apache----fileupload .Orialiy – COS – 2008() .Jsp-smart-upload – 200M. 用fileupload上传文件: 需要导入第三方包: Apache-fileupload.jar – 文件上传核心包. Apache-commons-io.jar – 这个包是fileupload的依赖包.同时又是一个工具包. 使用springmvc,解决烦人的post乱码问题,新建maven项目: maven依赖: <depe

FileUpload系列:(2)文件上传示例

示例 package com.rk.web.servlet; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException;