182x Posted July 14, 2007 Share Posted July 14, 2007 Hey guys, I have created an upload file script for a form however if the user does not upload a file I do not want the file upload part of the script to be used. Is there a way to check if the file type on the form is empty? Thanks. Link to comment https://forums.phpfreaks.com/topic/60009-check-for-file/ Share on other sites More sharing options...
ToonMariner Posted July 14, 2007 Share Posted July 14, 2007 if (!empty($_FILES))... Link to comment https://forums.phpfreaks.com/topic/60009-check-for-file/#findComment-298457 Share on other sites More sharing options...
182x Posted July 14, 2007 Author Share Posted July 14, 2007 hey thanks for the reply im a total newbie does that mean if there is not a file then do whatever? thanks again Link to comment https://forums.phpfreaks.com/topic/60009-check-for-file/#findComment-298458 Share on other sites More sharing options...
182x Posted July 14, 2007 Author Share Posted July 14, 2007 I am using the following structure but no matter what I do now it calls the last else and does not upload even if a file has been selected. Have I used the empty function in the wrong way? <?php session_start(); if(strlen($_POST['description']) > 4000) { //error msg } else{ if (!empty($_FILES)) { //upload } else { //don't upload } } ?> Link to comment https://forums.phpfreaks.com/topic/60009-check-for-file/#findComment-298469 Share on other sites More sharing options...
ToonMariner Posted July 15, 2007 Share Posted July 15, 2007 nope.. perhaps try referencing the fileupload fieldname if (!empty($_FILES['upfile']['name'])) ... where upfile is the name or id of the file input you used. Link to comment https://forums.phpfreaks.com/topic/60009-check-for-file/#findComment-298771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.