JangoF Posted April 29, 2007 Share Posted April 29, 2007 Hi, 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? :) Quote Link to comment Share on other sites More sharing options...
JangoF Posted April 30, 2007 Author Share Posted April 30, 2007 Anyone? Quote Link to comment Share on other sites More sharing options...
JangoF Posted April 30, 2007 Author Share Posted April 30, 2007 (edited) 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']); $index++; } 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 April 30, 2007 by JangoF Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.