Mime Type PDF php upload

I have this snippet

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"]);

When I try to upload the image it states that it isn't a permitted file type, when the file is a PDF document, is application/pdf the correct mime type?


You forgot to break before the default case :)

By the way, for the sake of answering your direct question, I've found myself referring back to this thread over and over again: Proper MIME media type for PDF files


Try this and

 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"]);

If won't solve your problem then tell us how do finfo_open and finfo_file functions look like.

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

上一篇: python和matplotlib服务器端来生成.pdf文件

下一篇: MIME类型PDF php上传