Jump to content

[SOLVED] PHP - Process page, then check if empty


Gamerz

Recommended Posts

Hello,

I have a php file uploader that has the form and php processing upload script embellished on the same script...I was wonder, how I can check if the user has uploaded a file, and if it hasn't, the script will die.

 

So far, I have this:

// If the $_FILES global IS INDEED empty and the password is set, continue
if (empty($_FILES['userfile']['name'])) {
   echo '$var is either 0, empty, or not set at all';
}

 

The code is indeed correct, but the thing is, since it's all in one script...the php checks if the $_FILES is empty...and obviously when you first go to my script, it will obviously provide the die error, since you havent uploaded any file...

 

but the thing is, since it's all in one script...the php checks if the $_FILES is empty...and obviously when you first go to my script, it will obviously provide the die error, since you havent uploaded any file..

 

Then you need to check to see if the form has been submitted before applying that check.

There's a submit button in your form that the user clicks on it to upload his file. It looks like this:

 

<input type="submit" name="submitButton" value="upload file" />

 

To check if the form has been submitted:

 

if (isset($_POST['submitButton']))
{
if (empty($_FILES['userfile']['name'])) {
   echo '$var is either 0, empty, or not set at all';
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.