note: android 瀏覽器上傳相片 的問題

2014051915:03
**筆記,個人參考
**無特別整理


Android Browser 上傳相片時
Server 端收到的 mime 是 application/octet-stream
而非 image/jpeg 或 image/pjpeg


額外程式碼來處理:

//the uploaded file
$img = $_FILES['img'];

//array for type if octet
$realMime = array(
    'useNew' => false,
    'type' => ''
);

if($img['type'] == "application/octet-stream"){
    $imageMime = getimagesize($img['tmp_name']); // get temporary file REAL info
    $realMime['type'] = $imageMime['mime']; //set in our array the correct mime
    $realMime['useNew'] = true; //set to true for next if
}




CI 的話,修改 config/mime.php


                'gif'    =>    'image/gif',
                'jpeg'    =>    array('image/jpeg', 'image/pjpeg'),
                'jpg'    =>    array('image/jpeg', 'image/pjpeg'),
                'jpe'    =>    array('image/jpeg', 'image/pjpeg'),
                'png'    =>    array('image/png',  'image/x-png'),

改為

                'gif'   =>  array('image/gif', 'application/octet-stream'),
                'jpeg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
                'jpg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
                'jpe'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
                'png'    =>    array('image/png',  'image/x-png', 'application/octet-stream'),



參考

Android image file sent to php upload image file is application/octet-stream type and not image/jpeg?

SWFUpload with CI 1.5x.

Filetype not allowed" error on android devices #2278

 


  •    (悄悄話) 2F
  • <悄悄話留言,不公開>
  •    (悄悄話) 1F
  • <悄悄話留言,不公開>