上传使用 
 iphone拍摄的图像时,我有一个问题. 
 
我试图使用 PHP和imgrotate函数自动决定是否需要将图像旋转到正确的位置,然后再将其上传到服务器.
我试图使用 PHP和imgrotate函数自动决定是否需要将图像旋转到正确的位置,然后再将其上传到服务器.
我的HTML代码:
<form class="form-horizontal" method="post" enctype="multipart/form-data">  
     <div class="form-group">
        <div class="col-md-9">
            <div class="input-group">
                <span class="input-group-btn">
                    <span class="btn btn-default btn-file">
                        Choose img<input type="file" name="file" id="imgInp">
                    </span>
                </span>
            </div>
        </div>
    </div>
    <button type="submit">Send</button>
</form> 
 我正在使用的PHP代码:
还返回错误:警告:imagerotate()期望参数1是资源,字符串在.
任何人都有这个场景的工作代码?
<?PHP
$filename = $_FILES['file']['name'];
$exif = exif_read_data($_FILES['file']['tmp_name']);
 if (!empty($exif['Orientation'])) {
        switch ($exif['Orientation']) {
            case 3:
                $image = imagerotate($filename,-180,0);
                break;
            case 6:
                $image = imagerotate($filename,90,0);
                break;
            case 8:
                $image = imagerotate($filename,-90,0);
                break;
        } 
    }
    imagejpeg($image,$filename,90);
?>
 您正在使用imagerotate错误.在传递文件名时,它希望第一个参数是资源.检查 
 manual 
  
 
                    
                    
                试试这个:
<?PHP
$filename = $_FILES['file']['name'];
$filePath = $_FILES['file']['tmp_name'];
$exif = exif_read_data($_FILES['file']['tmp_name']);
if (!empty($exif['Orientation'])) {
    $imageResource = imagecreatefromjpeg($filePath); // provided that the image is jpeg. Use relevant function otherwise
    switch ($exif['Orientation']) {
        case 3:
        $image = imagerotate($imageResource,180,0);
        break;
        case 6:
        $image = imagerotate($imageResource,0);
        break;
        case 8:
        $image = imagerotate($imageResource,0);
        break;
        default:
        $image = $imageResource;
    } 
}
imagejpeg($image,90);
?> 
 不要忘记通过添加以下两行来释放内存:
imagedestroy($imageResource); imagedestroy($image);