我想在php上传pdf或doc文件,我不想将它存储在数据库中,而是存储在文件系统中。但我歌厅一个错误,当我尝试这样做,..... 这里是我的代码上传文件和存储到php中的文件系统
if(isset($_POST['submit'])){
$allowedExts = array("pdf", "doc","docx");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "'application/pdf")
|| ($_FILES["file"]["type"] == " application/x-pdf")
|| ($_FILES["file"]["type"] == "application/acrobat")
|| ($_FILES["file"]["type"] == "applications/vnd.pdf")
|| ($_FILES["file"]["type"] == "text/pdf")
|| ($_FILES["file"]["type"] == "text/x-pdf"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
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";
}
}
?>
我不知道,如果该文件被上传在那里,但是当文件不是PDF文档或返回错误..请帮忙吗?
当我编辑这个它工作正常
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
你有什么错误? –
我没有得到一个错误...我认为文件上传,但我不知道在哪里可以找到他们 – internally1