上传图片用的复制--获取文件的前缀..

来源:互联网 发布:哈尔滨网络电视台 编辑:程序博客网 时间:2024/06/17 15:33

这是获取上传的文件名后再进行复制处理的函数
这里写图片描述

/**     * 复制文件     *     * @param string $imagesPath  公共文件的目录     * @param string $articlePathFile 要上传到的目录     * @param string $size 图片大小,例130_     * @param string $post post过来的值     * @param string $prefix 文件前缀     * @return boolean     */    function upfile($imagesPath,$articlePathFile,$size,$post,$prefix){            //生成当天的文件夹            $time = time();            $date = date('Ymd',$time);            //获取post值,并判断            //准备要复制文件路径            $articlePathFiles = $articlePathFile.$prefix.'/'.$date.'/'.$post;            //获取前缀            $prefix = substr($size.$post,0,strpos($size.$post,'_')+1);            //无前缀的路径            $articlePath = $articlePathFile.$prefix;            //查看目录            if(!file_exists($articlePath)){                //创造前缀路径                mkdir($articlePath);                //创建带前缀的时间路径                $articlePath = $articlePathFile.$prefix.'/'.$date;                mkdir($articlePath);            }else{                //创建时间路径                $articlePath = $articlePathFile.$prefix.'/'.$date;                mkdir($articlePath);            }            //准备公共图片的文件地址            $imagesPaths = $imagesPath.$size.$post;            //查看是否有重名文件            if(file_exists($articlePathFiles)){                $random = random(3,0);                //如果有,在前面加一个3位随机码                $articlePathFiles = $articlePathFile.$prefix.'/'.$date.'/'.$random.$size.$post;            }            //复制到目录            copy($imagesPaths,$articlePathFiles);            //删除源文件            @unlink($imagesPaths);        }
0 0