So I posted an earlier question here: upload
And I tried the solutions but now no matter if it's the correct filetype or not, it just says "invalid file". Here's my html:
<form action="upload_file.php" method="post" enctype="multipart/form-data" target="my_iframe">
Select a file: <input type="file" name="upload">
<input type="submit">
</form>
And here's my upload_file.php:
$allowedExts = array("doc", "docx");
$extension = end(explode(".", $_FILES["file"]["upload"]));
if (($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["upload"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("Proposals/" . $_FILES["file"]["upload"]))
{
echo $_FILES["file"]["upload"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"Proposals/" . $_FILES["file"]["upload"]);
echo "Stored in: " . "Proposals/" . $_FILES["file"]["upload"];
}
}
} else {
echo "Invalid file";
}
I've also tried:
$extension = pathinfo( $_FILES["file"]["upload"], PATHINFO_EXTENSION);
And did a
die($extension);
On both of them but nothing gets printed. So I have two questions
1) What is wrong with my above code
2) How do I hide the iframe until I receive a response? and then have like a okay button on it to make it go away once the user has read the response? Here's the iframe code if it helps:
<iframe name="my_iframe" src="upload_file.php"></iframe>