MIME类型PDF php上传

我有这个片段

if ($_FILES['tax']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error " . $_FILES['tax']['error']);
}
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime = finfo_file($finfo, $_FILES['tax']['tmp_name']);
    $ok = false;
    switch ($mime) {
        case 'image/gif':
        case 'application/pdf':
        case 'image/png':
        $ok = true;
        default:
    die("Unknown/not permitted file type");
    }
    move_uploaded_file($_FILES["tax"]["tmp_name"],"pints/" . $_FILES["tax"]["name"]);

当我尝试上传图像时,它指出它不是允许的文件类型,当文件是PDF文档时, application/pdf是正确的MIME类型?


您在默认情况下忘记了休息:)

顺便说一句,为了回答你的直接问题,我发现自己一遍又一遍地重复这个线程:适用于PDF文件的MIME媒体类型


试试这个和

 if ($_FILES['tax']['error'] !== UPLOAD_ERR_OK)
        die("Upload failed with error " . $_FILES['tax']['error']);

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime = finfo_file($finfo, $_FILES['tax']['tmp_name']);
    $ok = false;
    switch ($mime) {
        case 'image/gif':
        break;
        case 'application/pdf':
        break;
        case 'image/png':
            $ok = true;
        break;
        default:
            die("Unknown/not permitted file type");
        break;
    }
    move_uploaded_file($_FILES["tax"]["tmp_name"],"pints/" . $_FILES["tax"]["name"]);

如果不能解决您的问题,请告诉我们finfo_openfinfo_file函数的外观如何。

链接地址: http://www.djcxy.com/p/8177.html

上一篇: Mime Type PDF php upload

下一篇: Upload DOC or PDF using PHP