php image rotate upload

Solutions on MaxInterview for php image rotate upload by the best coders in the world

showing results for - "php image rotate upload"
Henrietta
16 Nov 2020
1    //START Update the user image
2if(isset($_POST['user_image_id'])){
3
4    $upload_image_id = $_POST['user_image_id'];
5    $user_image = $_FILES['user_image']['name'];
6    $filePath = $_FILES['user_image']['tmp_name'];
7
8   $image = imagecreatefromstring(file_get_contents($_FILES['user_image']['tmp_name']));
9    $exif = exif_read_data($filePath);
10    if(!empty($exif['Orientation'])) {
11        switch($exif['Orientation']) {
12           case 8:
13               $image = imagerotate($image,90,0);
14               break;
15           case 3:
16               $image = imagerotate($image,180,0);
17               break;
18           case 6:
19               $image = imagerotate($image,-90,0);
20               break;
21       }
22   }
23    // $image now contains a resource with the image oriented correctly
24
25    //create image target to upload
26    $image_target = $folder_target.basename($_FILES['user_image']['name']);
27
28    //upload the image the and update the name of the image
29    if(move_uploaded_file($_FILES['user_image']['tmp_name'], $image_target)){
30        if ($conn->query("UPDATE `users` SET `image`='$user_image' WHERE `id` LIKE '$upload_image_id'")){
31            echo 1;
32        }else{
33            echo "not update the name, Proplem";
34        }
35    }else{
36        echo 'image not uploaded';
37    }
38
39}
40