开发者

Php problem checking file upload value

Ok this might be a simple problem but I cannot figure this out at all.... I am trying to check if the user is trying to upload a file, upload it else execute some other code, but:

if(isset($_FILES['rv_img']['name']) && !empty($_FILES['rv_img']))
        {
            echo "here ";print_r($_FILES);
                }
else
                {
                        echo "no file uploaded";
      开发者_如何学JAVA          }

I want to see "no file uploaded" cause I am submitting the form with blank file input field.. but instead I am getting:

here Array ( [rv_img] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [thumb_img] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) 


try this

if ( isset($_FILES["file"]) && $_FILES["file"]["error"]==0 )
{
  $file_name= $_FILES["file"]["name"];
  move_uploaded_file($_FILES["file"]["tmp_name"], YOUR PATH TO STORE FILE. $_FILES["file"]["name"]);
}
else
echo("No file uploaded");


if(isset($_FILES['rv_img']['name']) && !empty($_FILES['rv_img']['name'])) 


That's because !empty($_FILES['rv_img']) will always return true. Try with !empty($_FILES['rv_img']['name']).


You get the error code 4, which is UPLOAD_ERR_NO_FILE constant. All the file upload error constants can be seen at http://php.net/manual/en/features.file-upload.errors.php. Try checking this condition:

if (... && $_FILES['rv_img']['error'] == UPLOAD_ERR_OK) { ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜