Php $u FILES数组在';函数中使用了什么?

Php $u FILES数组在';函数中使用了什么?,php,file-upload,Php,File Upload,我正在从用户上传表单调整图像的大小,我已将$\u文件数组的内容传递给我的调整大小功能。该函数使用GD调整图像大小并将其保存在所需目录中 我需要做两个图像副本:一个大副本和一个小副本的缩略图。当我第二次尝试调用该函数(但尺寸不同)以生成缩略图图像时,问题就出现了。对于$\u文件数组,我收到一条未识别索引数组消息 $\u文件数组在传递给函数后是否会自动删除,尽管我没有使用函数清除它 函数调用如下 if ($_FILES['image']['error'] != 4){ foto($_FILES

我正在从用户上传表单调整图像的大小,我已将
$\u文件
数组的内容传递给我的调整大小功能。该函数使用GD调整图像大小并将其保存在所需目录中

我需要做两个图像副本:一个大副本和一个小副本的缩略图。当我第二次尝试调用该函数(但尺寸不同)以生成缩略图图像时,问题就出现了。对于
$\u文件
数组,我收到一条
未识别索引
数组消息

$\u文件
数组在传递给函数后是否会自动删除,尽管我没有使用函数清除它

函数调用如下

   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';}}
/*foto函数、foto上传、保存位置、fotowidth、fotosize、*/
函数foto($\文件、$THUMBS\目录、$MAX\宽度、$MAX\高度){
/*生成随机名称*/
$fecha=time();$passpart1=$fecha;$passpart2=mt_rand(11000);$ps=$passpart1.$passpart2;$ps2=$passpart1.$passpart2.thumb';$thumbref='0';
如果(是否上载了文件($文件['tmp\U名称]]))
{
/*调整大小比率*/
$original=$_文件['tmp_名称'];
列表($width,$height,$type)=getimagesize($original);

如果($width我很确定这是因为$\u文件是超全局的,因此当您在函数foto中使用它作为参数名时,它会被删除,因此$\u文件将成为您作为第一个参数传递的任何内容

在$\文件之外,使用变量重写foto函数,例如:

function foto($image, $THUMBS_DIR, $MAX_WIDTH, $MAX_HEIGHT){
    // rest of code here with $_FILES changed to $image
}
或者,由于$\u文件是一个超级全局文件,您可以完全跳过将其用作参数,将调用更改为:

foto($THUMBS_DIR, 400, 400, 1)
以及以下形式的功能:

function foto($THUMBS_DIR, $MAX_WIDTH, $MAX_HEIGHT){
   //code placeholder 
   if (is_uploaded_file($_FILES['image']['tmp_name'])) {       
       $original = $_FILES['image']['tmp_name'];
   //rest of code
}

你能发布你代码的相关部分吗?一定要检查文件的大小不超过
upload\u max\u filesize
post\u max\u size
ini-directive扫描你包含了相关的功能吗?非常有用!非常感谢。我接受了你的第二个建议,工作得很辛苦,没有伤脑筋。罗伯特