Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Function to remove product image


Recommended Posts



I'm looking for a very simple function or code that will automatically remove a product image + thumbnail permanently from the server.


Basically what I had in mind is when I change the status to something when I edit an order (orders.php) and click on update, it should also delete the product image and thumbnail, as I no longer need them.


Can anyone help with this? :)

Link to comment
Share on other sites

Well as per usual it was up to me to try to fix this. Not much support getting from this forum.


Anyway for those of you who wonder how to do this:


	   //delete the product image(s)
  $index = 0;
  $order_packslip_query = tep_db_query("select op.products_id, op.orders_products_id, p.products_id, p.products_quantity, p.products_image from " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_PRODUCTS . " p where op.products_id = p.products_id and op.orders_id = '" . (int)$oID . "'");
  while ($order_packslip_data = tep_db_fetch_array($order_packslip_query)) {
  $packslip_products[$index] = array('qty' => $order_packslip_data['products_quantity'],
									'image' => $order_packslip_data['products_image']);

		for ($i=0, $n=sizeof($packslip_products); $i<$n; $i++) {
		if (file_exists(DIR_FS_CATALOG_IMAGES . $packslip_products[$i]['image']) && ($packslip_products[$i]['qty'] == '0')) {
		@unlink(DIR_FS_CATALOG_IMAGES . $packslip_products[$i]['image']);
		//delete the thumbnails
		$file = eregi_replace( '\.([a-z]{3,4})$', "-68x100.\\1", $packslip_products[$i]['image'] );
		if (file_exists(DIR_FS_CATALOG_IMAGES . $file) && ($packslip_products[$i]['qty'] == '0')) {
			@unlink(DIR_FS_CATALOG_IMAGES . $file);


It will only delete the images if the image exists AND the product quantity is 0.

You need to fix the regular expression (eregi_replace) to whatever syntax you use for your thumbnails, or just remove that section if you don't use thumbnails.


I use this in orders.php, but it should be fine using on whatever Admin page you want.

Edited by JangoF
Link to comment
Share on other sites

Join the conversation

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

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...