圖像被壓縮,但它會存儲在任何腳本文件夾,但我想存儲圖像特定給定的目錄。我想壓縮圖像到特定目錄
$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";
}
}
如果您問好英語問題並另外解釋代碼問題,您的問題更有可能得到解答。 – Blackbam
sure @Blackbam。 – rajsree