PHP File upload thumbnail path analysis class

Source: Internet
Author: User
Tags php file upload

<?php//文件上传时分析路径信息//author:songzhenghe 2014-1-24//version 0.1classpath_ana {    private$data_root;    private$web_root;    private$http_domain;    private$file;    private$r;        publicfunction__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    publicfunctioninit($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    privatefunctionstr_replace_once($needle,$replace,$haystack) {        $pos=strpos($haystack,$needle);        if($pos===false) return$haystack;        returnsubstr_replace($haystack,$replace,$pos,strlen($needle));    }    //    publicfunctionrename_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/< C7/>[7] = common/upload/2013/08/345349534.jpg    [8] = common/upload/2013/08/    [9] = = E:/wwwroot2/cms /    [Ten] = common/upload/    [one] = Http://www.cms.com/common/upload/2013/08/345349534.jpg    [12] = >/common/upload/2013/08/345349534.jpg    [] = e:/wwwroot2/cms/common/upload/2013/08/345349534.jpg)

PHP File upload thumbnail path analysis class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.