Checking the loading of multiple PHP files

Let's say I have a form like this:

<form action="upload.php" method="post" enctype="multipart/form-data"> File 1 : <input type="file" name="file[]" /> File 2 : <input type="file" name="file[]" /> <input type="submit" name="submit" value="Upload" /> </form> 

I want every file to have a download file.

Here is my condition and the code I'm writing:

File 1 is empty:

 if(empty($_FILES['file']['name'][0])) { echo 'file 1 empty'; } 

File 2 is empty:

 if(empty($_FILES['file']['name'][1])) { echo 'file 2 empty'; } 

File 1 and file 2 are empty:

 if(empty($_FILES['file']['name'][0]) && ($_FILES['file']['name'][1])) { echo 'file 1 and file 2 empty'; } 

Is it possible to write the above condition for a loop? Or just writing code alone is enough?

+5
source share
1 answer

use foreach

 $i=1 foreach($_FILES['file']['name'] as $file){ if(empty($file)) { echo "file $i empty"; $i++ } } 
+6
source

Source: https://habr.com/ru/post/1237028/


All Articles