I am new to php and is trying to construct a file upload script that will only allow pdf file
i am using the following codes for my form.php
and the following for the upload.php
when i run it on localhost it shows the file uploaded successfully
but when i run it on server it gives the message Invalid File
please help me regarding it
i am using the following codes for my form.php
PHP:
<form action="upload.php" method="post"
enctype="multipart/form-data">
<h4>Single File Upload<br />
</h4>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br /><br />
<input type="submit" name="submit" value="Submit" />
</form>
PHP:
<?php
if (($_FILES["file"]["type"] == "application/pdf")
&& ($_FILES["file"]["size"] < 200000))
{
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("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
when i run it on localhost it shows the file uploaded successfully
but when i run it on server it gives the message Invalid File
please help me regarding it