Page 1 of 1

Upload script not accepting text files

Posted: Tue Oct 05, 2010 3:52 pm
by attila001122
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:

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";
}
?>

Re: Upload script not accepting text files

Posted: Tue Oct 05, 2010 3:55 pm
by VladSun
Try adding

Code: Select all

echo $_FILES["file"]["type"]; 
in the very beginning of the code above to see what file types you are receiving. Then change them as appropriate.

Re: Upload script not accepting text files

Posted: Tue Oct 05, 2010 4:57 pm
by attila001122
Hi, thanks.

I was adding the line you suggested, and the result is : application/unknown.

I only guess, that it does not recogmise the .doc.

But I don't know why.

Re: Upload script not accepting text files

Posted: Tue Oct 05, 2010 5:17 pm
by VladSun
[Linux specific]
In my Apache config file (/etc/apache2/mods-available/mime.conf) I have a directive
[text]TypesConfig /ec/mime.conf[/text]

In mime.conf I have (beside the hundreds of the others):
[text]application/msword doc dot[/text]

Do you have these?

Re: Upload script not accepting text files

Posted: Wed Oct 06, 2010 4:59 am
by attila001122
I could not find the mime.conf...

So uploading files need to be configured on the server?