2013-01-22 127 views
2

我有這個片段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類型?

+0

[適用於PDF文件的MIME類型]可能的副本(http://stackoverflow.com/questions/312230/proper-mime-type-for-pdf-files) –

+0

$ mime = $ _FILES [「file」] [「type」] – zszen

回答

5

你忘了默認情況下:)

順便說之前突破,爲回答您的問題直接的緣故,我發現自己一遍又一遍再參照這個線程:Proper MIME media type for PDF files

+0

我檢查了這個問題,這就是爲什麼我對它是否正確感到困惑。但是謝謝你!忘記休息是問題! – kira423

1

試試這個,

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功能樣子。