使用 php 上传 Pdf 或 doc 或 docx 文件
Pdf or doc or docx file upload using php
您好,我在网上找到了用于上传 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>';
}
}
}
}
?>
我该怎么做?
检查 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,例如。 "application/msword" .doc 扩展名。
您好,我在网上找到了用于上传 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>';
}
}
}
}
?>
我该怎么做?
检查 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,例如。 "application/msword" .doc 扩展名。