下面是我的代碼,我試過,但有證據顯示一些警告錯誤:如何在使用php上傳圖像時壓縮多個圖像大小?
警告:和getimagesize(C:\ XAMPP \ tmp目錄\ php2F0B.tmp):未能打開流:在沒有這樣的文件或目錄C:\ xampp \ htdocs \ maahima \ admin \ uploadBulkImages.php on line 55
警告:imagejpeg()需要參數1爲資源,字符串在C:\ xampp \ htdocs \ maahima \ admin \ uploadBulkImages.php中給出在線66
我想要代碼插入壓縮圖像批量文件夾中的圖像。
<?php
if(isset($_FILES['file']['tmp_name'])){
$pro_image = $_FILES['file']['tmp_name'];
$no_of_file = count($_FILES['file']['tmp_name']);
$name = ''; $type = ''; $size = ''; $error = '';
for($i=0;$i < $no_of_file;$i++){
if(! is_uploaded_file($_FILES['file']['tmp_name'][$i])){
header("location:add_products.php?error=er8r5r");
}
else{
if(move_uploaded_file($_FILES['file']['tmp_name'][$i],"../products/".$_FILES['file']['name'][$i])){
if ($_FILES["file"]["error"][$i] > 0) {
$error = $_FILES["file"]["error"];
}
else {
$image="";
$error = "Uploaded image should be jpg or gif or png";
$url = '../smallSize-Image/'.$_FILES['file']['name'][$i];
echo $url;
$source_url=$_FILES["file"]["tmp_name"][$i];
$destination_url=$url;
$quality=12;
$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;
$buffer = file_get_contents($url);
/* Force download dialog... */
//header("Content-Type: application/force-download");
//header("Content-Type: application/octet-stream");
//header("Content-Type: application/download");
// header("location:add_products.php?succcess=s8sc5s");
/* Don't allow caching... */
// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
/* Set data type, size and filename */
//header("Content-Type: application/octet-stream");
//header("Content-Length: " . strlen($buffer));
//header("Content-Disposition: attachment; filename=$url");
/* Send our file... */
echo $buffer;
}
}
else{
header("location:add_products.php?error=er8r5r");
}
}
}
}
else{
}
?>
你在HTML表單中是否有適當的表單標籤?它是否具有enctype = multipart/form-data? –