I have searched all over the internet on the possibility to upload a pdf file using php script. I tried all the suggestions given in this site and it didn’t work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Uploaded</title>
</head>
<body>
<?php
//ini_set("upload_max_filesize", 10000000);
$uploaddir = './uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
//$allowed_ext = "pdf";
//$max_size = "9000000000000000000000";
define('MAX_FILE_SIZE', 0);
echo "<p>";
if((($_FILES["userfile"]["type"] == "image/gif")
|| ($_FILES["userfile"]["type"] == "image/jpeg")
|| ($_FILES["userfile"]["type"] == "image/png" )
|| ($_FILES["userfile"]["type"] == "image/jpg")
|| ($_FILES["userfile"]["type"] == "application/msword")
|| ($_FILES["userfile"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["userfile"]["type"] == "text/plain")
|| ($_FILES["userfile"]["type"] == "application/wordperfect6.0")
|| ($_FILES["userfile"]["type"] == "application/pdf"))
&& ($_FILES["userfile"]["size"] < 10000000))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
</body>
</html>
try to print the type recongnized of your file in the else statement instead of simply printing “Upload failed”.
Maybe the tyope recognized is not one belonging to the types specified in the if.