Gamerz Posted September 9, 2009 Share Posted September 9, 2009 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... Link to comment https://forums.phpfreaks.com/topic/173623-solved-php-process-page-then-check-if-empty/ Share on other sites More sharing options...
trq Posted September 9, 2009 Share Posted September 9, 2009 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. Link to comment https://forums.phpfreaks.com/topic/173623-solved-php-process-page-then-check-if-empty/#findComment-915196 Share on other sites More sharing options...
Gamerz Posted September 9, 2009 Author Share Posted September 9, 2009 How do I check if the form is submitted? Link to comment https://forums.phpfreaks.com/topic/173623-solved-php-process-page-then-check-if-empty/#findComment-915208 Share on other sites More sharing options...
asmith Posted September 9, 2009 Share Posted September 9, 2009 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'; } } Link to comment https://forums.phpfreaks.com/topic/173623-solved-php-process-page-then-check-if-empty/#findComment-915210 Share on other sites More sharing options...
Gamerz Posted September 9, 2009 Author Share Posted September 9, 2009 Alright thank you. Link to comment https://forums.phpfreaks.com/topic/173623-solved-php-process-page-then-check-if-empty/#findComment-915212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.