uploadify 后台处理程序

/********
uploadify 后台处理程序
Date:2012-06-24  by: pooy
blog:www.pooy.net
①:把上次完成的图片文件名返回给前台
②:把上次完成的图片裁剪缩略图
*******/
//首先判断文件是否为空
if (!empty($_FILES)) {
    //把上次完成的图片文件名返回给前台
    //'name' 就是之前写 《jquery.uploadify动态传递表单元素》里面动态附加值
    echo $_FILES['Filedata']['name'];
    $tmpDir = $_POST['note'];
    $fileName = iconv("UTF-8","GB2312",$_FILES["Filedata"]["name"]);
    //echo $fileName;
    $file = $_FILES["Filedata"]["tmp_name"];
    //fwrite($f,$tmpDir);
    //复制原图
    $path = "uptemp/".$tmpDir."_org/";
    //echo $path;
    if(!is_dir($path))
       mkdir($path);
    if (copy($file, $path . $fileName)){
        $_ft =$file;
    }else{
        $_ft ="no";
    }
    //生成缩略图
    $fileName = str_replace(" ","\ ",$fileName);
    //$fileName = iconv("UTF-8","GB2312",$_GET['newname']);
    $pathTmb = "uptemp/".$tmpDir."/";
    $extPos = strrpos($fileName,".");
    $secfile= substr($fileName,0,$extPos);
    $tmbName = $secfile.".jpg";
    if(!is_dir($pathTmb))
       mkdir($pathTmb);
    //echo $pathTmb."<br>";
    if(!file_exists($pathTmb.$tmbName)){
        //IMAGEMAGICKDIR这个就要根据您自己装的imagemagick目录来写了
        $cmd = IMAGEMAGICKDIR."/convert -resize 110x110 ". $path.$fileName." ".$pathTmb.$tmbName;
    //echo $cmd;
    system( $cmd );
    }
    $tmbName = str_replace("\ "," ",$tmbName);
    readfile($pathTmb.$tmbName);
    exit;
    //转码
    $fileName = iconv("GB2312","UTF-8",$secfile);
}
// 获取文件扩展名
// @param $fileName 上传文件的原文件名
    function getExt($fileName){
        $ext = explode(".", $fileName);
        $ext = $ext[count($ext) - 1];
        return strtolower($ext);
    }

发表评论