Jump to content
techker

IMG Rotate And destroy

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

 

Share this post


Link to post
Share on other sites

The source image is a filename contained in the $image variable, right?

Share this post


Link to post
Share on other sites

Okay, so... problem solved?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.