unlink - Deleting a product with related pictures with PHP -
In my PHP application I have products that have images in 3 sizes - large, thumbnails, and small thumbnails. Is stored in separate folders:
Images - / Gallery thumbnails - / Gallery / Large thumbnails Small thumbnails - / Gallery / Thumbs
Each product has its own unique ID The file names of all images are the same. The path of images for the product is being stored in the database with the identical id of the product ID stored in the database.
Each product can have more than one image but in the database, where I store the path and the name of the images for each product, all the images are stored in the same ID, similar to the product ID Are there. Therefore, if there are 2 images in the product database with ID 56, then those images will be stored like this:
ID-> 56, image1name, bigthumb1name, thumb1name ID- > 56, image2name, bigthumb2name, thumb2name
What am I trying to do - Delete all the images associated with the product being removed. The code I have written is as follows:
$ imagename_query = mysql_query ("Select image from gallery id = '$ productivity'", $ connect); $ Imagename_result = mysql_fetch_array ($ imagename_query); Forex currency ($ imagename_result $ as imagename) {$ bigimage = "../gallery/$imagename"; ($ Bigimage) Unlink; $ Picture = "../gallery/bigthumbs/$imagename"; Unlink ($ Picture); $ Thumb = "../gallery/thumbs/$imagename"; Unlink to ($ thumb); } $ Gallery_query = mysql_query ("Delete from gallery WHERE id = '$ productid'", $ connect); $ Query = mysql_query ("remove products from id = '$ productid'", $ connect); The problem is that the above code only removes 1 image - there is no difference, how many images are there with the same ID.
Can anyone help me?
Thanks in advance.
This line problem is $ imagename_result = mysql_fetch_array ($ imagename_query ); should be
while ($ line = mysql_fetch_array ($ imagename_query)) {$ bigimage = "../gallery/{$row['image ']} "; ($ Bigimage) Unlink; // etc} I'm not sure this is the truth for your case - do you have many products with the same name?
Your attitude may be a little risky. ..You can make folder path unique by embedding product ID
/ gallery / {$ product_id} / {$ product_name}. *
Comments
Post a Comment