php上传pdf,doc,docx

时间:2015-02-16 19:30:45

标签: php forms file-upload

我尝试将文件上传到我的服务器,允许的扩展名应为pdf,doc,docx 这是我的代码。

$uploadCv = $_FILES['uploadCv']['name'];
    $target = "includes/employeeCv/";
    $target = $target . basename($_FILES['uploadCv']['name']);
    if ($_FILES['uploadCv']['size'] == 0) {
        $error['uploadCvErr'] = "<span class='notAllowed'>Please upload your c.v</span>";
    } elseif
    (
        $_FILES['uploadCv']['type'] != 'application/pdf'
        && $_FILES['uploadCv']['type'] != 'application/msword'
        && $_FILES['uploadCv']['type'] != 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
    ) {
        $error['uploadCvErr'] = 'Unsupported file type uploaded.';
    } elseif ($_FILES['uploadCv']['size'] > 5000000) {
        $error['uploadCvErr'] = 'File uploaded exceeds maximum upload size.';
    }

PDF和文档一切正常,但在docx上它说Unsupported file type uploaded.

我在这里做错了什么。

修改 我把它添加到我的检查文件中 && $_FILES['uploadCv']['type'] != 'application/zip' 仍然没有工作。

1 个答案:

答案 0 :(得分:2)

OfficeOpenXML .docx文件通常具有application/zip mime类型,因为它们是XML文件的压缩集合,并且浏览器在设置mime类型时懒得检查超出zip签名