多文件上载不起作用,也不是is_upload_file

时间:2011-12-20 01:17:04

标签: php image image-upload is-uploaded-file

我似乎无法让这件事正常工作,我会认为我拥有它而其他东西不会起作用。看看......

我正在尝试上传多个文件,这里是我的php,因为它始终表示该文件存在问题,如果我删除is_uploaded_file,它就不起作用。

include('image.php');
$image = new SimpleImage();

foreach(array_keys($_FILES['ref']['name']) as $i) { 

    if (is_uploaded_file($_FILES['ref']['name'][$i])) {
        $time = date("fYhis");
        $destination="./../img/treatments/" .$pageid. "/refimgs";
        $tdestination="./../img/treatments/" .$pageid. "/refimgs/thumbs";
        $image->load($_FILES['ref']['name'][$i]);
        $image->save($destination . '/' .$time . $i . '.jpg');    
        $image->resizeToWidth(140); 
        $image->save($tdestination . '/' .$time . $i . '.jpg');

    }else{ echo "Possible file upload attack: ";
        echo "filename '". $_FILES['ref']['name'][$i] . "'.";
    }
}

1 个答案:

答案 0 :(得分:1)

您必须在$_FILES['ref']['tmp_name']函数中使用is_uploaded_file。 更新后的代码行如下所示:

include('image.php');
$image = new SimpleImage();
foreach(array_keys($_FILES['ref']['name']) as $i) { 

    if (is_uploaded_file($_FILES['ref']['tmp_name'][$i])) {
        $time = date("fYhis");
        $destination="./../img/treatments/" .$pageid. "/refimgs";
        $tdestination="./../img/treatments/" .$pageid. "/refimgs/thumbs";
        $image->load($_FILES['ref']['name'][$i]);
        $image->save($destination . '/' .$time . $i . '.jpg');      
        $image->resizeToWidth(140);   
        $image->save($tdestination . '/' .$time . $i . '.jpg');

   }else{ echo "Possible file upload attack: ";
       echo "filename '". $_FILES['ref']['name'][$i] . "'.";
   }
}

注意:客户端计算机中文件的name在服务器上无效,您必须使用tmp_name。 希望这可以帮助您解决问题。