上传Excel文件到服务器

我无法将msofficefile upload到服务器上的文件夹,我可以上传.pdf和图片文件,但不能上传.docx,.xlsx甚至.txt文件,但是从我的有限知识来看,我的所有语法都是正确的。 这是表格

<form id="Upload" action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="fileSelect">Navigate and choose:</label> <input type="file" name="file" id="fileSelect"><br><br> <input class="button" type="submit" name="action" value="Upload to Shared Folder"> </form> 

这是upload_file.php

  if(isset($_FILES["file"]["error"])){ if($_FILES["file"]["error"] > 0){ echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else{ $allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png", "doc" => "application/msword", "docx" => "application/msword", "xls" => "application/vnd.ms-excel", "xlsx" => "application/vnd.ms-excel", "pdf" => "application/pdf", "txt" => "application/txt"); $filename = $_FILES["file"]["name"]; $filetype = $_FILES["file"]["type"]; $filesize = $_FILES["file"]["size"]; // siati faaopoopo $ext = pathinfo($filename, PATHINFO_EXTENSION); if(!array_key_exists($ext, $allowed)) die("Error: This file is not an accepted file type.</br></br>"); // siati fua - 10MB $maxsize = 200000 * 60; if($filesize > $maxsize) die("Error: File size is larger than the allowed 10MB limit.</br></br>"); // siati MYME if(in_array($filetype, $allowed)){ // Check whether file exists before uploading it if(file_exists("general/" . $_FILES["file"]["name"])){ echo $_FILES["file"]["name"] . " already exists. Go back and choose another file or rename the original.</br></br>"; } else{ move_uploaded_file($_FILES["file"]["tmp_name"], "general/" . $_FILES["file"]["name"]); echo "The file was uploaded successfully.</br></br>"; } } else{ echo "Error: There was a problem uploading the file - please try again."; } } } else{ echo "Error: Invalid parameters - something is very very very wrong with this upload."; } 

我一定会错过一些东西,但还没有弄清楚什么。 我试着在stackexchange和google上查找application / msword和东西,但是这一切似乎都是正确的。 我得到的错误是:

  Error: There was a problem uploading the file - please try again. 

请协助

您可能检查错误的mimetype,尝试转储文件无法上传的所有mimetypes。

以下是ms office mimetypes的简要概述: office_mime_types

如果你想让你的文件检查更好,更安全,你可以像这样检查。

 $allowed = array( "xls" => array( "application/vnd.ms-excel" ), "xlsx" => array( "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) ); // replace this if ( in_array( $filetype, $allowed ) ) {} // with this // this checks also if mimetype of xlsx is just a mimetype of xlsx and nothing else if ( isset( $allowed[$ext] ) && in_array( $filetype, $allowed[$ext] ) ) {}