3

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?

kira423
  • 325
  • 1
  • 3
  • 25

2 Answers2

7

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

Community
  • 1
  • 1
Lim H.
  • 9,049
  • 9
  • 43
  • 70
  • I checked out that question that's why I was confused about if it was right or not. But thank you! Forgetting the breaks was the problem! – kira423 Jan 22 '13 at 03:33
2

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.

Davit
  • 1,340
  • 5
  • 20
  • 47