ios端浏览器拍照上传到服务器,图片被旋转90度 php 解决方案

1、可以通过前端进行解决,本案例通过后端解决的

判断请求的浏览器的ua,如果是ios浏览器则进行90度旋转

 public function upload()
    {
        $file = $this->request->file('file');
        if (empty($file)) {
            $this->error(__('No file upload or server upload limit exceeded'));
        }
        //判断浏览器类型
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
		    try{
				$exif = @exif_read_data($_FILES['file']['tmp_name']);
				$image = imagecreatefromstring(file_get_contents($_FILES['file']['tmp_name']));
				//旋转90度
				$image = imagerotate($image, -90, 0);
			    imagejpeg($image, $_FILES['file']['tmp_name']);
			    imagedestroy($image);
			}catch(\Exception $e){
				//echo $e->getMessage();
			}
		}

  

猜你喜欢

转载自www.cnblogs.com/pxjbk/p/11869436.html