When I'm testing this code I keep coming up with an error - Invalid File.
I have restrictions on file types and size but id doesn't matter what size or type, keeps giving the error. Any suggestions?
Thanks!
Here's the code I am working with:
<?php
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/pdf") || ($_FILES["file"]["type"] == "image/tif")) && ($_FILES["file"]["size"] < 100000000)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1000000) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
//if (file_exists("upload/" . $_FILES["file"]["name"])) {
if (file_exists("UPLOADED_FILES/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
//move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], "UPLOADED_FILES/" . $_FILES["file"]["name"]);
echo "Stored in: " . "UPLOADED_FILES/" . $_FILES["file"]["name"];
//copy-pasta some sendmail code from the contact form below this comment
$toAddress = "emailaddress@gmail.com"; //sends email to this address
$subject = "Files have been uploaded to FTP site"; //email subject
//now send confirmation to the user
$userContent = "Files have been uploaded to FTP site.\n\n"
$headers = 'From: '.$toAddress."\r\n".'Reply-To: '.$toAddress;
mail($toAddress, $subject, $userContent, $headers);
}
}
} else {
echo "Invalid file";
}
?>