I'm trying to make a File Management System, the upload form and the php action is the same file, I've followed everything correctly and yet I get the same error:
Warning: finfo_file(): Empty filename or path in /Applications/XAMPP/xamppfiles/htdocs/Year1/Period2/Project/Assignments/WS_FileManagement/Upload.php on line 10
Resource id #2Allowed types: .png, .jpeg, .jpg, .gif
upload
I did upload the correct type.
I am trying to upload a random image from the internet (put on my desktop) but it doesn't work, please help.
Here's the code:
<?php
if(isset($_GET['submit']))
{
if($_FILES['imagefile']['size'] < 3000000)
{
$accepted = ["image/png", "image/jpeg", "image/jpg", "image/gif"];
$fileinfo = finfo_open(FILEINFO_MIME_TYPE);
$fileType = finfo_file($fileinfo, $_FILES["imagefile"]["tmp_name"]);
echo $fileinfo;
echo $fileType;
if(in_array($fileType, $accepted))
{
if($_FILES['imagefile']['error']>0)
{
echo "<br>Error: ". $_FILES['imagefile']['error']."<br>";
}
else
{
if(file_exists("images/".$_FILES['imagefile']['name']))
{
echo $_FILES['imagefile']['name']." already exists";
}
else
{
if(move_uploaded_file($_FILES['fimagefileile']['tmp_name'], "images/".$_FILES['file']['name']))
{
echo "Success!";
}
else
{
echo "Something went wrong!";
}
}
}
}
else
{
echo "Allowed types: .png, .jpeg, .jpg, .gif";
}
}
else
{
echo "Please upload a file under 3MB!";
}
}
?>
/images is in the same folder as the file
EDIT:
$fileinfo returns false! why?