Jump to content

IMG Rotate And destroy


techker

Recommended Posts

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="" />

 

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.