<?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);
        $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;
    }
    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
)

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

  1. Spring MVC文件上传下载工具类

    import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import ...

  2. 文件上传: FileItem类、ServletFileUpload 类、DiskFileItemFactory类

    文件上传: ServletFileUpload负责处理上传的文件数据,并将表单中每个输入项封装成一个FileItem对象中, 在使用ServletFileUpload对象解析请求时需要根据DiskFi ...

  3. SFTP 文件上传下载工具类

    SFTPUtils.java import com.jcraft.jsch.*; import com.jcraft.jsch.ChannelSftp.LsEntry; import lombok.e ...

  4. tp5下的文件上传与下载类

    class FieldInterfun extends Controller { /** * [upload 上传文件] * @param [type] $file [description] * @ ...

  5. 小兔Java教程 - 三分钟学会Java文件上传

    今天群里正好有人问起了Java文件上传的事情,本来这是Java里面的知识点,而我目前最主要的精力还是放在了JS的部分.不过反正也不麻烦,我就专门开一贴来聊聊Java文件上传的基本实现方法吧. 话不多说 ...

  6. struts2实现文件上传(多文件上传)及下载

    一.要实现文件上传,需在项目中添加两个jar文件 二.上传准备的页面 注:必须植入enctype="multipart/form-data"属性,以及提交方式要设置成post &l ...

  7. 【Java EE 学习 72 上】【数据采集系统第四天】【增加调查logo】【文件上传】【动态错误页指定】【上传限制】【国际化】

    增加logo的技术点:文件上传,国际化 文件上传的功能在struts2中是使用文件上传拦截器完成的. 1.首先需要在页面上添加一个文件上传的超链接. 点击该超链接能够跳转到文件上传页面.我给该表单页面 ...

  8. chunkupload 文件上传断点续传组件(java) - 正式发布

    chunkupload简介 chunkupload是一款基于java语言的断点续传组件,针对文件上传,非文件下载,集成方便,使用简单. chunkupload实现如下功能: ·  实现断点续传 ·  ...

  9. 我心中的核心组件(可插拔的AOP)~分布式文件上传组件~基于FastDFS

    回到目录 一些概念 在大叔框架里总觉得缺点什么,在最近的项目开发中,终于知道缺什么了,分布式文件存储组件,就是缺它,呵呵,对于分布式文件存储来说,业界比较公认的是FastDFS组件,它自己本身就是集群 ...

随机推荐

  1. 字典 & 列表表达式 结合

    题: 思路: 要求的结果是小字典里面的两个值组成的列表,所以只要抓到小字典,这个题就可以用列表推导式直接表达了.所 以把小字典设为元素d,然后用d在列表里面遍历,列表呢,是大字典的一个值. 答案:  

  2. IDEA 使用技巧 Update

    IDEA使用起来和Eclipse很大区别. 1.快捷键. 因为一个个熟悉起来费时间,就直接在Preferences—keymap里选择了Eclipse OS X,这样快捷键就转换到了Mac下Eclip ...

  3. 本地项目关联git仓库

    Command line instructions Git global setup git config --global user.name "zhoushuo" git co ...

  4. java.sql.SQLException: Incorrect string value: '\xE5\xB0‘

    mysql插入中文字符报java.sql.SQLException: Incorrect string value: '\xE5\xB0‘ #原因:由于默认情况下,mysql的字符集是latin1(I ...

  5. [BJWC2011]最小三角形

    嘟嘟嘟 这一看就是平面分治的题,所以就想办法往这上面去靠. 关键就是到\(mid\)点的限制距离是什么.就是对于当前区间,所有小于这个距离的点都选出来,参与更新最优解. 假设从左右区间中得到的最优解是 ...

  6. Python自动化之form验证二

    class LoginForm(forms.Form): user = fields.CharField() pwd = fields.CharField(validators=[]) def cle ...

  7. windows下安装redis并设置自启动

    一.下载windows版本的Redis 去官网找了很久,发现原来在官网上可以下载的windows版本的,现在官网以及没有下载地址,只能在github上下载,官网只提供linux版本的下载 官网下载地址 ...

  8. VC++获取当前路径及程序名的实现代码

    VC上或取当前路径有多种方法,最常用的是使用 GetCurrentDirectory和GetModuleFileName函数,个中都有诸多注意事项,特别总结一下 一.获取当前运行目录的绝对路径 1.使 ...

  9. orcale字段

    ---数据类型 /* 1  数字 number [小数,整数] number(5,3)表示总共5个数字,小数点后3个,最大值99.999 number(5) 表示整数  最大值99999 2  字符 ...

  10. Linux VFS的主要的数据结构

    先说明一下,linux内核中各种数据结构也不停的在变,所以不同版本的内核各个数据结构的定义可能会差别很大,这一组关于linux 文件系统的文章中的代码都摘自linux-2.6.34.1. VFS依赖于 ...