2013-06-19 66 views
0

我想在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")) 
+0

你有什么错误? –

+0

我没有得到一个错误...我认为文件上传,但我不知道在哪里可以找到他们 – internally1

回答

0

你有没有设置上传文件夹权限775?

另外,尝试:

$allowedExts = array("pdf", "docx"); 
$extension = end(explode(".", $_FILES["file"]["name"])); 
if ((($_FILES["file"]["type"] == "application/pdf") 
|| ($_FILES["file"]["type"] == "application/msword") 

玩弄,使用MIME Types

+0

我该怎么做? – internally1

+0

在本地主机上使用您的文件管理器(FTP或网站CP) – Laurent

+0

,那么我是否需要创建此上传文件夹?我在哪里创建它? – internally1

0

当您上传文档或PDF时,它会返回错误,因为这是您允许文件具有的唯一扩展名。你在 $ allowedExts = array(“pdf”,“doc”,“docx”);

相关问题