2
votes

There is something confusing me. When I use input[type=file] to upload images in different mobile, I get different reponse in the server.

Here is the different response:

My question is that why i am uploading the image, but I do not get the same response in the server.

<form  action="#" method="post" class='c-image-change-form' enctype="multipart/form-data">
            <!-- <div class="oh jiaBtn active"> -->
            <div class="oh jiaBtn">
                <div class="oh pa">
                    <p id="id_img_list">
                        <a href="javascript:;" class="last" id="id_last_img_wrap">
                            <img src="http://cache.hinabian.com/mobile/images/jia3.png" alt="添加照片" />
                            <input name="upfile" type="file" class="file pa" id='id_upfile' accept="image/*" />
                        </a>

                    </p>
                </div>
            </div>
            <div class="tc imgNum"><span class="color999">最多添加<em>9</em>张照片</span></div>
        </form>

array ( 'upfile' => array ( 'name' => '16460', 'type' => 'application/octet-stream', 'tmp_name' => '/tmp/phpErjuTZ', 'error' => 0, 'size' => 1627225, ), )

array ( 'upfile' => array ( 'name' => 'IMG_20151030_124751.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpOAHfmc', 'error' => 0, 'size' => 2090488, ), )

1
What makes you think input type=file is HTML5?? It's been part of HTML since 1995. - Simba
Is it just the type=>application/octet-stream vs type=>image/jpeg that is worrying you, or are you expecting the other properties to be the same as well? - Simba
yes,I just want to know that what happen between the type=>application/octet-stream and type=>image/jpeg , or image/png and so on. - jamesxu-e.g.
It's just different browsers behaving differently. Nothing you can do about it. You certainly shouldn't rely on the mime type being accurate; it may not be. You should always verify what type of file it is for yourself, without relying on the mime type. - Simba
Hi, Simba. If I am not rely on mimi type , so what I do to handle this situation. - jamesxu-e.g.

1 Answers

0
votes

// Just use php's function imagecreatefromstring to create a picture, them imagepng ,imagejpg , imagejpeg to save a picture , then use it.

private function _imageCreateFromString($data)
{
     $res = imagecreatefromstring($data);
     if($res !== false)
     {
           //header('Content-Type: image/png');
           imagepng($data);
           imagedestroy($res);
     }
}