0

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";
                }

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 ) ) 

4 Answers 4

1

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");
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

Comments

0

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) { ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.