您好以下编码我在网上找到pdf文件上传。但我需要它上传doc和docx文件也与重命名文件。以下是代码。
<?php
$pdfPath = "docmument_upload/";
$maxSize = 102400000000;
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['upload_pdf'])) {
if (is_uploaded_file($_FILES['filepdf']['tmp_name'])) {
if ($_FILES['filepdf']['type'] != "application/pdf") {
echo '<p>This is not Docuent or pdf File</p>';
} else if ($_FILES['filepdf']['size'] > $maxSize) {
echo '<p class="error">To large file: ' . $maxSize . 'KB</p>';
} else {
$menuName = 'file.doc';
$result = move_uploaded_file($_FILES['filepdf']['tmp_name'], $pdfPath . $menuName);
if ($result == 1) {
echo '<p class="error">Uploaded</p>';
} else {
echo '<p class="error">Uploading fail</p>';
}
}
}
}
?>
我该怎么做?
答案 0 :(得分:0)
检查http://www.freeformatter.com/mime-types-list.html上的mime类型并修改行:
if ($_FILES['filepdf']['type'] != "application/pdf") {
为:
if ($_FILES['filepdf']['type'] != "application/pdf" OR $_FILES['filepdf']['type'] != "typename2" OR $_FILES['filepdf']['type'] != "typename3) {
其中typename是您选择的mimetypes,例如。 &#34;应用程序/ msword&#34;对于.doc扩展名。