我正在调整用户上传表单的图像大小,并且已将$_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