Page 1 of 1

File Upload Check

Posted: Sat Sep 08, 2012 9:33 pm
by Da_Elf
I want that when your adding a new entry that there are three files that MUST be uploaded when you click the Add submit button. The code should be simple but its not working.

Code: Select all

if(isset($_POST['add'])){
     if ((!isset ($_FILES['file1'])) || (!isset ($_FILES['file2'])) || (!isset ($_FILES['file3'])) ){	
          echo "no files were selected";
     } else {
          //other code
     }
}

Re: File Upload Check

Posted: Sat Sep 08, 2012 10:38 pm
by Christopher
What does the code actually do? With the code below, what is the output?

Code: Select all

if(isset($_POST['add'])){
     if ((!isset ($_FILES['file1'])) || (!isset ($_FILES['file2'])) || (!isset ($_FILES['file3'])) ){	
          echo "no files were selected";
     } else {
          echo "All files selected";
     }
} else {
     echo "Not add";
}

Re: File Upload Check

Posted: Sat Sep 08, 2012 10:44 pm
by Da_Elf
i dont need the last else. if in my form i have no files selected and i click add it does the 1st else and echos "All files selected". it should echo the 1st echo of "No files selected" since none of the files were set by my use of !isset

Re: File Upload Check

Posted: Sat Sep 08, 2012 11:22 pm
by Da_Elf
here is the full thing. you can copy paste and run it. If you have no files selected it will tell you that you have all files selected which isnt true

Code: Select all

<?php
//Add Files
if(isset($_POST['add'])){
if ((!isset ($_FILES['file1'])) || (!isset ($_FILES['file2'])) || (!isset ($_FILES['file3'])) ){	
	echo "no files were selected";
	}
else {
	echo "all files selected";
	}
}//close Add Files
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form name="filestest" action="test.php" method="post" enctype="multipart/form-data">
<input name="file1" type='file'><br />
<input name="file2" type='file'><br />
<input name="file3" type='file'><br />
<input type="submit" name="add" value="Add" class="subs" />
</form>
</body>
</html>

Re: File Upload Check

Posted: Sun Sep 09, 2012 12:08 pm
by Da_Elf
ok i went with this

Code: Select all

if (($_FILES['file1']['name'] == '' ) || ($_FILES['file2']['name'] == '' ) || ($_FILES['file3']['name'] == '' ) ){

Re: File Upload Check

Posted: Sun Sep 09, 2012 1:14 pm
by McInfo
If no file was uploaded for "file1", then $_FILES['file1']['error'] == UPLOAD_ERR_NO_FILE. See Error Messages Explained.