Upload script not accepting text files
Posted: Tue Oct 05, 2010 3:52 pm
Hi,
I am about using a script to upload files to the server.
I have find the script as a tutorial, and it works well as it is.
I have added two lines, to include .doc and .txt for accept text documents too.
But I got the "invalid file" message when I try to upload these.
Anyone can help?
The script is below (thanks)
These are tha added lines:
The whole script:
I am about using a script to upload files to the server.
I have find the script as a tutorial, and it works well as it is.
I have added two lines, to include .doc and .txt for accept text documents too.
But I got the "invalid file" message when I try to upload these.
Anyone can help?
The script is below (thanks)
These are tha added lines:
Code: Select all
|| ($_FILES["file"]["type"] == "text/txt")
|| ($_FILES["file"]["type"] == "text/doc")The whole script:
Code: Select all
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "text/txt")
|| ($_FILES["file"]["type"] == "text/doc")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
{
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"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("uploadtest/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploadtest/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>