2016-11-16 63 views
1

圖像被壓縮,但它會存儲在任何腳本文件夾,但我想存儲圖像特定給定的目錄。我想壓縮圖像到特定目錄

$name = ''; $type = ''; $size = ''; $error = ''; 
function compress_image($source_url, $destination_url, $quality) { 

     $info = getimagesize($source_url); 

      if ($info['mime'] == 'image/jpeg') 
      $image = imagecreatefromjpeg($source_url); 

      elseif ($info['mime'] == 'image/gif') 
      $image = imagecreatefromgif($source_url); 

      elseif ($info['mime'] == 'image/png') 
      $image = imagecreatefrompng($source_url); 

      imagejpeg($image, $destination_url, $quality); 
      return $destination_url; 
     } 
    if ($_POST) { 
      $upload_image = $_FILES["file"][ "name" ]; 
      if ($_FILES["file"]["error"] > 0) 
      { 
      $error = $_FILES["file"]["error"]; 
      } 
      else if (($_FILES["file"]["type"] == "image/gif") || 
      ($_FILES["file"]["type"] == "image/jpeg") || 
      ($_FILES["file"]["type"] == "image/png") || 
      ($_FILES["file"]["type"] == "image/pjpeg")) { 

      $url = $upload_image; 
      $filename = compress_image($_FILES["file"]["tmp_name"], $upload_image, 80); 


      // if(move_uploaded_file($image, $target_dir.$url)) 
      { 
       echo "uploaded success"; 
      } 
     }else { 
      $error = "Uploaded image should be jpg or gif or png"; 
     } 
     } 
+0

如果您問好英語問題並另外解釋代碼問題,您的問題更有可能得到解答。 – Blackbam

+0

sure @Blackbam。 – rajsree

回答

0

更換

imagejpeg($image, $destination_url, $quality); 

imagejpeg($image, "<Your Path>/".$destination_url, $quality); 

EG。

imagejpeg($image, "uploads/".$destination_url, $quality); 
+0

謝謝你的工作@Gopal – rajsree

+0

mypath像這樣我給它下面不工作 $ destination_url = $ _ SERVER ['DOCUMENT_ROOT']。'/ mysite/uploadimages /'; imagejpeg($ image,$ destination_url,$ quality); – rajsree