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 to make sure that each file had upload file.
Here is my condition and the code that I write:
File 1 empty:
if(empty($_FILES['file']['name'][0]))
{
echo 'file 1 empty';
}
File 2 empty:
if(empty($_FILES['file']['name'][1]))
{
echo 'file 2 empty';
}
File 1 and File 2 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 in for loop? Or just seperately write the code is enough?
Definition and Usage. The move_uploaded_file() function moves an uploaded file to a new destination. Note: This function only works on files uploaded via PHP's HTTP POST upload mechanism. Note: If the destination file already exists, it will be overwritten.
php $dir = dirname(__FILE__); echo "<p>Full path to this dir: " . $dir . "</p>"; echo "<p>Full path to a . htpasswd file in this dir: " .
use foreach
$i=1
foreach($_FILES['file']['name'] as $file){
if(empty($file))
{
echo "file $i empty";
$i++
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With