我正在調整用戶上傳表單的圖像大小,並且已將$_FILES
數組的內容傳遞給了我的調整大小函數。該函數使用GD調整圖像大小並將其保存在所需的目錄中。
我需要製作兩個圖像副本:一個大副本和一個縮略圖的小副本。當我嘗試再次調用該函數(但具有不同的尺寸)來製作縮略圖圖像時,問題就出現了。我收到$_FILES
陣列的unidentified index
陣列消息。
$_FILES
數組在傳遞給函數後是否自動刪除,儘管我沒有使用函數來清除它?
FUNCION CALL如下
if ($_FILES['image']['error'] != 4){
foto($_FILES['image'], $THUMBS_DIR, 400, 400, 1);
foto($_FILES['image'], $THUMBS_DIR, 70, 70, 1);
}
功能
/*foto function, foto upload, where to save, fotowidth, fotosize,*/
function foto($_FILES, $THUMBS_DIR, $MAX_WIDTH, $MAX_HEIGHT){
/*generate random name*/
$fecha = time();$passpart1 = $fecha;$passpart2 = mt_rand(1, 1000);$ps = $passpart1.$passpart2;$ps2= $passpart1.$passpart2.'thumb';$thumbref='0';
if (is_uploaded_file($_FILES['tmp_name']))
{
/*resize ratio*/
$original = $_FILES['tmp_name'];
list($width, $height, $type) = getimagesize($original);
if ($width <= $MAX_WIDTH && $height <= $MAX_HEIGHT) {$ratio = 1;}
elseif ($width > $height) {$ratio = $MAX_WIDTH/$width;}
else {$ratio = $MAX_HEIGHT/$height;}
$imagetypes = array('/\.gif$/','/\.jpg$/','/\.jpeg$/','/\.png$/');
$name = preg_replace($imagetypes, '', basename($original));
$name=$ps;switch($type)
{case 1:$source = @ imagecreatefromgif($original);if (!$source) {$result = 'Cannot process GIF files. Please use JPEG or PNG.';}break;
case 2:$source = imagecreatefromjpeg($original);break;
case 3:$source = imagecreatefrompng($original);break;
default:$source = NULL;$result = 'Cannot identify file type.';}
if (!$source) {$result = 'Problem copying original';}
else {
$thumb_width = round($width * $ratio);
$thumb_height = round($height * $ratio);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
switch($type)
{case 1:if (function_exists('imagegif')) {$success = imagegif($thumb, $THUMBS_DIR.$ps.'.gif');$thumb_name = $ps.'.gif';}
else {$success = imagejpeg($thumb, $THUMBS_DIR.$ps.'.jpg', 50);$thumb_name = $ps.'.jpg';}break;
case 2:$success = imagejpeg($thumb, $THUMBS_DIR.$ps.'.jpg', 100);$thumb_name = $ps.'.jpg';break;
case 3:$success = imagepng($thumb, $THUMBS_DIR.$ps.'.png');$thumb_name = $ps.'.png';}
/*destroy temp or not*/
if ($success) {$result = "$thumb_name created";}
}
$fotref = $thumb_name;
}
else{$errorreport='error with upload';}}
大家好我已經發布的代碼,我本來didnt張貼監守我沒有預料到人們希望看到它,我真的感謝它,感謝大家。
您可以發佈您的代碼的相關部分? – 2012-07-12 19:57:04
請務必檢查文件大小是否超過'upload_max_filesize'或'post_max_size' ini指令 – 2012-07-12 19:58:31
您能否包含相關函數? – 2012-07-12 19:59:34