1

I am currently working on shopping cart.let me quick expain whats happening in product_info.php page.

in product info page products information in displayed such as name,price,image etc..

i have made small functionality in this page.i have put 10 small diffrent color images below the product main image and 2 text boxes to write something on main image using php Gd.

i have made ajax function which is called on onclick of image small images and on onkeyup of two text boxes with three parameter : selected color image's path and value of textboxes.Now when user will click on the one of the color image or Write text in the text box then this function will call and the response will go in the img.php file in which the dynamic image is created using GD and stored in the folder(not in databse) with random image integer name and this image. and from img.php it will get in product info page and display in main image.this new image's path will store in session for when user done checkout then it will store in table.

same process will repleat when user select diffrent color or eneter diffrent value in text box and every time new image will create and save in folder.

my question is how woulld i unlink the previous image from folder when new image will create? Thanx In Advance.

Naitik Mistry
  • 299
  • 1
  • 2
  • 10
  • Try this: http://stackoverflow.com/questions/10006686/use-ajax-to-display-php-generated-image – GBD Nov 23 '12 at 09:06

4 Answers4

0

Your question is very hard to read, but overall

unlink($imageName);

Will delete the image, as documented here.

Since the file is already sent to the client, you can unlink it right away when the image needs to be updated (in img.php if I understood properly?).

emartel
  • 7,712
  • 1
  • 30
  • 58
0

When saving your GD image for the user, you need to use a key that can be linked to the user and the image and the colour. The when you unlink the image, you can search for that key, colour and image combo and remove it.

For example, save the images with a name like this: uid_imgId_colourId.ext. If you want to add a small random id, that may help as well, but add it to the end of the file name (before the .ext).

Tigger
  • 8,980
  • 5
  • 36
  • 40
0

Use unlink function to delete the image.

first check rather the file is there or not.

  unlink('\path\image_name1.png');
JackLB
  • 110
  • 9
-1

first check rather the file is there or not and after fetch image name in database

unlink("image path/imagename");