是PHP重画类的原因,还是flash的原因,很困惑,如果有遇到这样问题的朋友,请多多指教!我用的php 缩略图重画类是:..因为是网上找的,请多多指教

解决方案 »

  1.   

    class UploadFile{

    var $fileType;
    var $unAllowFileType;
    /**
     * Method:构造函数
     * Explain:$fileType,文件格式;支持多个格式用|隔开
     */
     function UploadFile($fileType){
     if($fileType == '' || !isset($fileType)){
         exit("未指定上传文件类型!");  
     }
     $this -> fileType = $fileType;
     $this -> unAllowFileType = "php|pl|cgi|asp|aspx|jsp|php3|shtm|shtml";
     }
     
        /**
     * Method:文件上传
     */
     function upload($formFileName,$path,$isOriName=0,$maxSize=2048000,$upType='image',$isDraw=0,$drawWidth=0,$drawHeight=0,$isResize=0,$resizeArr,$isWater=0){
             
     if(is_array($GLOBALS[$formFileName.'_name'])){//多文件上传
     
     for($i=0;$i<count($GLOBALS[$formFileName.'_name']);$i++){
     //判断文件是否通过 HTTP POST 上传
     if(is_uploaded_file($GLOBALS[$formFileName.'_tmp_name'][$i])){
     if($GLOBALS[$formFileName.'_error'][$i] != 4){
     //过滤不允许的文件格式
     if(eregi("\.(".$this -> unAllowFileType.")$",$GLOBALS[$formFileName.'_name'][$i])){
     exit('你上传的文件为系统禁止的类型!');
     }
     
     //判断文件格式是否正确
     if($upType == 'image'){
     if(!eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'][$i])){
     exit("你所上传的图片格式必须为:".$this -> fileType);
     }
     $typeArr = Array("image/pjpeg","image/jpeg","image/jpg","image/gif","image/png","image/xpng","image/wbmp");
     $fileTypes = strtolower(trim($GLOBALS[$formFileName.'_type'][$i]));
     
     if(!in_array($fileTypes,$typeArr)){
     exit("上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种!");
     }
     }elseif($upType == 'flash' && !eregi("\.swf$",$GLOBALS[$formFileName.'_name'][$i])){
     exit("你上传的必须为flash文件格式!");
     }elseif($upType == 'media' && !eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'][$i])){
     exit("你所上传的文件格式必须为:".$this -> fileType);
     }elseif($upType == 'file'){
     if(!eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'])){
     exit("你所上传的图片格式必须为:".$this -> fileType);
     }
     }else{
     exit("你所上传的文件类型不被允许!");
     }
     
     //判断文件是否超出限定大小
     if ($GLOBALS[$formFileName.'_size'][$i] > $maxSize) {
     $maxSizes = $maxSize/1024;
     exit("你所上传的文件大小不可超过$maxSizes K!");
     }
     
     //判断文件是否超过了 php.ini 中 upload_max_filesize 选项限制值
     if($GLOBALS[$formFileName.'_error'][$i] == 1){
     exit("你所上传的文件大小不可超过服务器允许的最大值!");
     }
     
     //判断文件大小是否超过了 HTML 表单中 MAX_FILE_SIZE 选项指定值
     if($GLOBALS[$formFileName.'_error'][$i] == 2){
     exit("你所上传的文件大小不可超过浏览器限定大小!");
     }
     
     if($GLOBALS[$formFileName.'_error'][$i] == 3){
     exit("文件只有部分被上传,可能是由于没有写入权限!");
     } 
     }
     }
     }  //开始上传文件
     $fileNameArr = '';
     for($i=0;$i<count($GLOBALS[$formFileName.'_name']);$i++){
     //判断文件是否通过 HTTP POST 上传
     if(is_uploaded_file($GLOBALS[$formFileName.'_tmp_name'][$i])){
     if($GLOBALS[$formFileName.'_error'][$i] != 4){
     if($isOriName){
     $fileName = mb_convert_encoding($GLOBALS[$formFileName.'_name'][$i],"gb2312","UTF-8");
     }else{
     $fileName = date("ymdhis".rand(1000,9999)).strrchr($GLOBALS[$formFileName.'_name'][$i],".");
     }
     
     @move_uploaded_file($GLOBALS[$formFileName.'_tmp_name'][$i],$path.$fileName) or die("文件只有部分被上传,可能是由于没有写入权限!");
     $fileNameArr[$i] = $fileName;
     
     //对原图重新绘制尺寸或生成缩图
     $this -> isDraw($fileName,$path,$isDraw,$drawWidth,$drawHeight,$isResize,$resizeArr);
     }
     }
     }
     
     return $fileNameArr;
     
     }else{//单文件上传
     //判断文件是否通过 HTTP POST 上传
     if(is_uploaded_file($GLOBALS[$formFileName.'_tmp_name'])){
     if($GLOBALS[$formFileName.'_error'] != 4){
      
     //过滤不允许的文件格式
     if(eregi("\.(".$this -> unAllowFileType.")$",$GLOBALS[$formFileName.'_name'])){
     exit('你上传的文件为系统禁止的类型!');
     }
     //判断文件格式是否正确
     if($upType == 'image'){
     if(!eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'])){
     exit("你所上传的图片格式必须为:".$this -> fileType);
     }
     $typeArr = Array("image/pjpeg","image/jpeg","image/gif","image/png","image/xpng","image/wbmp");
     $fileTypes = strtolower(trim($GLOBALS[$formFileName.'_type']));
     if(!in_array($fileTypes,$typeArr)){
     exit("上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种!");
     }
     }elseif($upType == 'flash' && !eregi("\.swf$",$GLOBALS[$formFileName.'_name'])){
     exit("你上传的必须为flash文件格式!");
     }elseif($upType == 'media' && !eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'])){
     exit("你所上传的文件格式必须为:".$this -> fileType);
     }elseif($upType == 'file'){
     if(!eregi("\.(".$this -> fileType.")$",$GLOBALS[$formFileName.'_name'])){
     exit("你所上传的图片格式必须为:".$this -> fileType);
     }
     }else{
     exit("你所上传的文件类型不被允许!");
     }
     
     //判断文件是否超出限定大小
     if ($GLOBALS[$formFileName.'_size'] > $maxSize) {
     $maxSizes = $maxSize/1024;
     exit("你所上传的文件大小不可超过$maxSizes K!");
     }
     
     //判断文件是否超过了 php.ini 中 upload_max_filesize 选项限制值
     if($GLOBALS[$formFileName.'_error'] == 1){
     exit("你所上传的文件大小不可超过服务器允许的最大值!");
     }
     //判断文件大小是否超过了 HTML 表单中 MAX_FILE_SIZE 选项指定值
     if($GLOBALS[$formFileName.'_error'] == 2){
     exit("你所上传的文件大小不可超过浏览器限定大小!");
     }
     
     if($GLOBALS[$formFileName.'_error'] == 3){
     exit("文件只有部分被上传,可能是由于没有写入权限!");
     }
     
     //开始上传文件
     if($isOriName){
     $fileName = mb_convert_encoding($GLOBALS[$formFileName.'_name'],"gb2312","UTF-8");
     }else{
     $fileName = date("ymdhis".rand(1000,9999)).strrchr($GLOBALS[$formFileName.'_name'],".");
     }
     
     @move_uploaded_file($GLOBALS[$formFileName.'_tmp_name'],$path.$fileName) or die("文件只有部分被上传,可能是由于没有写入权限!");
     
     //对原图重新绘制尺寸或生成缩图
     $this -> isDraw($fileName,$path,$isDraw,$drawWidth,$drawHeight,$isResize,$resizeArr);
     
     
     return $fileName;
     }else{
     exit("没有文件上传!");
     }
     }
     } 
     }
         
     /**
      * Method:是否重新绘制原图尺寸或生成缩图
      */
      //isDraw($fileName,$path,$isDraw,$drawWidth,$drawHeight,$isResize,$smallWidth,$smallHeight,$smallPath)
     function isDraw($fileName,$path,$isDraw,$drawWidth,$drawHeight,$isResize,$resizeArr){

    //重画
    if($isDraw){
     $newFile = substr($fileName,0,strpos($fileName,"."));
     $imgSize = getimagesize($path.$fileName);
     if($imgSize[0] > $drawWidth || $imgSize[1] > $drawHeight){
     $result = $this -> imgResize($path.$fileName,$newFile,$drawWidth,$drawHeight,$path);
     
     if($result['file_no'] == 3 || $result['file_no'] == 2){
     $newFile = $newFile.'.jpg';
     }else{
     $newFile = $newFile.'.gif';
     }
     rename($val['folder'].'/'.$newFile,$val['folder'].'/'.$fileName);
      }
     }
      

  2.   

     //生成缩略图
     if($isResize){
     $newFile = substr($fileName,0,strpos($fileName,"."));
     if(is_array($resizeArr)){
     foreach($resizeArr as $key => $val){
     $result = $this -> imgResize($path.$fileName,$newFile,$val['width'],$val['height'],$val['folder']);
     if($result['file_no'] == 3 || $result['file_no'] == 2){
     $newFile = $newFile.'.jpg';
     }else{
     $newFile = $newFile.'.gif';
     }
     rename($val['folder'].'/'.$newFile,$val['folder'].'/'.$fileName);
         }

     }
     }
     }
     
     /**
      * Method:生成缩略图
      */
     function imgResize($oriFilePath,$newFile,$maxWidth,$maxHeight,$newPath) {
    $info = getimagesize ( $oriFilePath );
    switch ($info [2]) {
    case 1 :
    $im = imagecreatefromgif ( $oriFilePath );
    break;
    case 2 :
    $im = imagecreatefromjpeg ( $oriFilePath );
    break;
    case 3 :
    $im = imagecreatefrompng ( $oriFilePath );
    break;
    default :
    $array_error ['file_name'] = $oriFilePath;
    $array_error ['if_eoor'] = "fail";
    $array_error ['file_no'] = $info [2];
    $array_error ['file_type'] = $info ['mime'];
    return $array_error;
    }
    if (! $im) {
    $array_error ['file_name'] = $oriFilePath;
    $array_error ['if_eoor'] = "fail";
    $array_error ['file_no'] = $info [2];
    $array_error ['file_type'] = $info ['mime'];
    return $array_error;
    }
    $width = imagesx ( $im );
    $height = imagesy ( $im );
    if (($maxWidth && $width > $maxWidth) || ($maxHeight && $height > $maxHeight)) {
    $RESIZEWIDTH = false;
    $RESIZEHEIGHT = false;
    if ($maxWidth && $width > $maxWidth) {
    $widthratio = $maxWidth / $width;
    $RESIZEWIDTH = true;
    }
    if ($maxHeight && $height > $maxHeight) {
    $heightratio = $maxHeight / $height;
    $RESIZEHEIGHT = true;
    }
    if ($RESIZEWIDTH && $RESIZEHEIGHT) {
    if ($widthratio < $heightratio) {
    $ratio = $widthratio;
    } else {
    $ratio = $heightratio;
    }
    } elseif ($RESIZEWIDTH) {
    $ratio = $widthratio;
    } elseif ($RESIZEHEIGHT) {
    $ratio = $heightratio;
    }
    if ($ratio > 0) {
    $newwidth = $width * $ratio;
    $newheight = $height * $ratio;
    } else {
    $newwidth = $maxWidth;
    $newheight = $maxHeight;
    }
    if (function_exists ( "imagecopyresampled" )) {
    $newim = imagecreatetruecolor ( $newwidth, $newheight );
    imagecopyresampled ( $newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
    } else {
    $newim = imagecreate ( $newwidth, $newheight );
    imagecopyresized ( $newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
    }

    if ($info [2] == 1)
    imagepng ( $newim, $newPath . $newFile . ".gif" );
    else if ($info [2] == 2)
    imagepng ( $newim, $newPath . $newFile . ".jpg" );
    else if ($info [2] == 3)
    imagepng ( $newim, $newPath . $newFile . ".jpg" );

    ImageDestroy ( $newim );
    } else {
    if ($info ["mime"] == "image/gif")
    imagepng ( $im, $newPath . $newFile . ".gif" );
    elseif ($info ["mime"] == "image/pjpeg" || $info ["mime"] == "image/jpeg")
    imagepng ( $im, $newPath . $newFile . ".jpg" );
    }
    $array_error ['file_name'] = $oriFilePath;
    $array_error ['if_eoor'] = "pass";
    $array_error ['file_no'] = $info [2];
    $array_error ['file_type'] = $info ['mime'];
    return $array_error;
    }
     
     /**
      * Method:生成水印图
      */
     function createWater($imgSrc,$Img,$Text,$TextColor,$Pos,$fontType,$Type){
            
    $srcInfo = @getimagesize($imgSrc);

    $srcImg_w    = $srcInfo[0];
    $srcImg_h    = $srcInfo[1];

    switch ($srcInfo[2]){
    case 1:
    $srcim =imagecreatefromgif($imgSrc);
    break;
    case 2:
    $srcim =imagecreatefromjpeg($imgSrc);
    break;
    case 3:
    $srcim =imagecreatefrompng($imgSrc);
    break;
    default:
    die("不支持的图片文件类型");
    exit;
    }

    if(!strcmp($Type,"img")){
    if(!file_exists($Img) || empty($Img)){ 
    return;
    }

    $ImgInfo = @getimagesize($Img);

    $Img_w    = $ImgInfo[0];
    $Img_h    = $ImgInfo[1];
       
    if($srcImg_w < $Img_w || $srcImg_h < $Img_h){
    return;
    }

    switch ($ImgInfo[2]){
    case 1:
    $im =imagecreatefromgif($Img);
    break;
    case 2:
    $im =imagecreatefromjpeg($Img);
    break;
    case 3:
    $im =imagecreatefrompng($Img);
    break;
    default:
    die("不支持的水印图片文件类型");
    exit;
    }
       
    $logow = $Img_w;
    $logoh = $Img_h;
    }
       
    if(!strcmp($Type,"text")){
    $fontSize = 16;
    if(!empty($Text)){
    if(!file_exists($fontType)){
    return;
    }
    }else{
    return;
    }
       
    $box = @imagettfbbox($fontSize, 0, $fontType,$Text);
    $logow = max($box[2], $box[4]) - min($box[0], $box[6]);
    $logoh = max($box[1], $box[3]) - min($box[5], $box[7]);
    }
       
    if($Pos == 0){
    $Pos = rand(1, 9);
    }
       
    switch($Pos){
    case 1:
    $x = +5;
    $y = +5;
    break;
    case 2:
    $x = ($srcImg_w - $logow) / 2;
    $y = +5;
    break;
    case 3:
    $x = $srcImg_w - $logow - 5;
    $y = +15;
    break;
    case 4:
    $x = +5;
    $y = ($srcImg_h - $logoh) / 2;
    break;
    case 5:
    $x = ($srcImg_w - $logow) / 2;
    $y = ($srcImg_h - $logoh) / 2;

    break;
    case 6:
    $x = $srcImg_w - $logow - 5;
    $y = ($srcImg_h - $logoh) / 2;
    break;
    case 7:
    $x = +5;
    $y = $srcImg_h - $logoh - 5;
    break;
    case 8:
    $x = ($srcImg_w - $logow) / 2;
    $y = $srcImg_h - $logoh - 5;
    break;
    case 9:
    $x = $srcImg_w - $logow - 5;
    $y = $srcImg_h - $logoh -5;
    break;
    default:
    die("此位置不支持");
    exit;
    }
       
    $dst_img = @imagecreatetruecolor($srcImg_w, $srcImg_h);
       
    imagecopy ( $dst_img, $srcim, 0, 0, 0, 0, $srcImg_w, $srcImg_h);
       
    if(!strcmp($Type,"img")){
    imagecopy($dst_img, $im, $x, $y, 0, 0, $logow, $logoh);
    imagedestroy($im);

    }
       
    if(!strcmp($Type,"text")){
    $rgb = explode(',', $TextColor);
       
    $color = imagecolorallocate($dst_img, $rgb[0], $rgb[1], $rgb[2]);
    imagettftext($dst_img, $fontSize, 0, $x, $y, $color, $fontType,$Text);
    }
       
    switch ($srcInfo[2]){
    case 1:
    imagegif($dst_img, $imgSrc);
    break;
    case 2:
    imagejpeg($dst_img, $imgSrc);
    break;
    case 3:
    imagepng($dst_img, $imgSrc);
    break;
    default:
    die("不支持的水印图片文件类型");
    exit;
    }
      
    imagedestroy($dst_img);
    imagedestroy($srcim);
    }
    }