techker Posted November 12, 2018 Share Posted November 12, 2018 Hey guy's i have a script i did a few months ago and now noticed that it is doing its job but keeps the old file ..so i got the image a few times but on a different angle... how can i optimize this code to delete the old image when doing the rotation? <?php session_start(); include_once 'dbconnect.php'; if (!isset($_SESSION['userSession'])) { header("Location: index.php"); } $degrees = -270; $path = $_GET['Folder']; $file =$_GET['Pic']; $fileid =$_GET['id']; $image = $path.'/'.$file; $imageN = $path.'/New_'.$file; //load the image $source = imagecreatefromjpeg($image); //rotate the image $rotate = imagerotate($source, $degrees, 0); $NewImg='New_'.$file ; //set the Content type //header('Content-type: image/jpeg'); //display the rotated image on the browser //imagejpeg($rotate); imagejpeg($rotate,$imageN,100); //free the memory imagedestroy($source); imagedestroy($rotate); $sql = "UPDATE Coupon_list SET product_image_thumb = '$NewImg' WHERE id = '$fileid'"; if (mysqli_query($DBcon, $sql)) { echo "Rotation ok"; echo('<script language="Javascript">opener.window.location.reload(false); window.close();</script>'); } else { echo "Error Rotating: " . mysqli_error($DBcon); } mysqli_close($DBcon); ?> <img src="gears.gif" alt="" /> Quote Link to comment https://forums.phpfreaks.com/topic/307887-img-rotate-and-destroy/ Share on other sites More sharing options...
requinix Posted November 12, 2018 Share Posted November 12, 2018 The source image is a filename contained in the $image variable, right? Quote Link to comment https://forums.phpfreaks.com/topic/307887-img-rotate-and-destroy/#findComment-1562105 Share on other sites More sharing options...
techker Posted November 22, 2018 Author Share Posted November 22, 2018 correct Quote Link to comment https://forums.phpfreaks.com/topic/307887-img-rotate-and-destroy/#findComment-1562355 Share on other sites More sharing options...
requinix Posted November 22, 2018 Share Posted November 22, 2018 Okay, so... problem solved? Quote Link to comment https://forums.phpfreaks.com/topic/307887-img-rotate-and-destroy/#findComment-1562358 Share on other sites More sharing options...
techker Posted November 22, 2018 Author Share Posted November 22, 2018 ya i think just need to unlink the old file Quote Link to comment https://forums.phpfreaks.com/topic/307887-img-rotate-and-destroy/#findComment-1562376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.