How to check that user has upload any file or not in php

Here I am showing full code That how to check that user has upload any file or not.

 

<!DOCTYPE html>
<html>
<body>

<form action=”#” method=”post” enctype=”multipart/form-data”>
Select image to upload:
<input name=”my_files[]” type=”file” multiple=”multiple” />
<input type=”submit” value=”Upload Image” name=”submit”>
</form>
<?php

if (isset($_FILES[‘my_files’]))
{
$myFile = $_FILES[‘my_files’];
$fileCount = count($myFile[“name”]);

for ($i = 0; $i <$fileCount; $i++)
{
$error = $myFile[“error”][$i];

if ($error == ‘4’) // error 4 is for “no file selected”
{
echo “no file selected”;
}
else
{

$name = $myFile[“name”][$i];
echo $name;
echo “<br>”;
$temporary_file = $myFile[“tmp_name”][$i];
echo $temporary_file;
echo “<br>”;
$type = $myFile[“type”][$i];
echo $type;
echo “<br>”;
$size = $myFile[“size”][$i];
echo $size;
echo “<br>”;
$target_path = “uploads/$name”; //first make a folder named “uploads” where you will upload files
if(move_uploaded_file($temporary_file,$target_path))
{
echo ” uploaded”;
echo “<br>”;
echo “<br>”;
}
else
{
echo “no upload “;
}
}
}
}
?>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *