I have a short bit of code to help combat the iOS EXIF issue with JPEG. This works great, it'll also upload PNG files too but it won't upload JPG files. The Session does get set but the image will not upload.
I found out that it will only accept JPEG and JPG on phones, it will not upload either on PC or Laptop.
<?php
session_start();
$target_dir = "uploads/";
$filename = $_FILES['file']['name'];
$filePath = $_FILES['file']['tmp_name'];
$types = array('image/jpeg');
if (in_array($_FILES['file']['type'], $types)) {
$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, -90, 0);
break;
case 8:
$image = imagerotate($imageResource, 90, 0);
break;
default:
$image = $imageResource;
}
}
imagejpeg($image, 'uploads/'.$filename, 100);
$_SESSION["image"] = $filename;
header("Location: http://perfectprints.org.uk/tool.php");
} else {
if (move_uploaded_file($_FILES['file']['tmp_name'], "uploads/". $_FILES["file"]['name'])) {
$_SESSION["image"] = $filename;
header("Location: http://perfectprints.org.uk/tool.php");
}
}
?>
This will upload JPEG with the EXIF fixes and PNG files but it won't upload JPG files. How do I fix this issue?
I'm guessing PHP is reading JPG and JPEG as the same file type and run through the EXIF code, maybe that destroys the JPG images?
Thank you.