Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Mar 2006
    Posts
    477
    Plugin Contributions
    0

    Default how to delete photos with SQL query?

    [Note: remember to include site URL, ZC version, list of plugins, PHP version, etc ... read the Posting Tips shown above for information to include in your post here. And, remove this comment before actually posting!]

    Is it possible to be able to delete photos from our server with a SQL code?

    We have alot of products and photos and when we have to delete just a few from a product its very hard to load all the photos and find them and delete them. We are looking for a simpler way to do this

    thanks
    We sell ATV, Dirtbike, Streetbike, Snowmobile, Watercraft & Custom stickers & Banners. Check us out www.AD-DiscountPerformance.com

  2. #2
    Join Date
    Aug 2014
    Location
    Lisbon
    Posts
    594
    Plugin Contributions
    0

    Default Re: how to delete photos with SQL query?

    Not sure if there is a plugin to do that.
    And it's a bit difficult to guess what images are product images or not.

    By in theory, one has to create a list of all products images from products table.
    All the rest would be deleted if not present in that list.
    However, there may be images, that are not from old products, and still in use for something else.
    Only if they are / were in a specific folder that you know, that only product images live there.
    “Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

  3. #3
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,846
    Plugin Contributions
    25

    Default Re: how to delete photos with SQL query?

    Edo a search for obsolete images in the plugin section.

  4. #4
    Join Date
    Mar 2006
    Posts
    477
    Plugin Contributions
    0

    Default Re: how to delete photos with SQL query?

    Quote Originally Posted by mesnitu View Post
    Not sure if there is a plugin to do that.
    And it's a bit difficult to guess what images are product images or not.

    By in theory, one has to create a list of all products images from products table.
    All the rest would be deleted if not present in that list.
    However, there may be images, that are not from old products, and still in use for something else.
    Only if they are / were in a specific folder that you know, that only product images live there.
    We have the names of the images we want to delete.
    We sell ATV, Dirtbike, Streetbike, Snowmobile, Watercraft & Custom stickers & Banners. Check us out www.AD-DiscountPerformance.com

  5. #5
    Join Date
    Jul 2012
    Posts
    16,735
    Plugin Contributions
    17

    Default Re: how to delete photos with SQL query?

    For what it's worth, the deletion of the actual files would not be done by a sql query. The database (affected by sql queries) contains the path to the file(s), not the files themselves.

    Design75 though referenced a plugin though I have a feeling that the thought was the missing images plugin:https://www.zen-cart.com/downloads.php?do=file&id=1887

    I searched for obsolete images and then tried just images and went through 6 pages of downloads without finding something that seemed to do the reverse of the missing images plugin.

    In absence of a plugin, you could delete the images by referencing them from a product and then in the admin request the image be deleted from the server, or manually through ftp, cPanel, a script that perhaps has the remove command before the file and it's path, etc... but not by a sql command. :)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Mar 2006
    Posts
    477
    Plugin Contributions
    0

    Default Re: how to delete photos with SQL query?

    Quote Originally Posted by mc12345678 View Post
    For what it's worth, the deletion of the actual files would not be done by a sql query. The database (affected by sql queries) contains the path to the file(s), not the files themselves.

    Design75 though referenced a plugin though I have a feeling that the thought was the missing images plugin:https://www.zen-cart.com/downloads.php?do=file&id=1887

    I searched for obsolete images and then tried just images and went through 6 pages of downloads without finding something that seemed to do the reverse of the missing images plugin.

    In absence of a plugin, you could delete the images by referencing them from a product and then in the admin request the image be deleted from the server, or manually through ftp, cPanel, a script that perhaps has the remove command before the file and it's path, etc... but not by a sql command. :)
    Well i usually use filezilla to delete images. but there are so many that it won't load them all. As for going into our cpanel and doing it. thats really time consuming and takes a very long time to load all the images in a browser.

    here is an example of what we are trying to do

    on this item https://ad-discountperformance.com/i...ucts_id=279281

    i need to delete just 3 of the sub images there.

    i don't want to do what we were doing is rename the ones we want and reupload more to the server.
    We sell ATV, Dirtbike, Streetbike, Snowmobile, Watercraft & Custom stickers & Banners. Check us out www.AD-DiscountPerformance.com

  7. #7
    Join Date
    Jul 2012
    Posts
    16,735
    Plugin Contributions
    17

    Default Re: how to delete photos with SQL query?

    How precisely do you know the image and path?

    You could create a php file, would suggest placing it in the admin so that it can't be accessed easily from the internet.

    Code:
    <?php
    require 'includes/application_top.php';
    
    if (!IS_ADMIN_FLAG) {
     die('Illegal Access');
    }
    
    $delete_photos = array(
    'path/file1',
    'path/file2',
    'path/file3'
    );
    
    foreach ($delete_photos as $photo) {
     unlink($photo);
    }
    Now, that assumes a full path.

    If your information is say based on being in the store's images directory, where you have say: attributes/prod1.jpg as the path, then:
    Code:
    unlink($photo);
    Could instead be:
    Code:
    unlink(DIR_FS_CATALOG_IMAGES . $photo);
    The generation of the array list should be relatively easy. Paste all of the paths, one per line. Add an apostrophe/single quote at the beginning of each. Add an apostrophe and comma at the end of each (may need to delete the last comma). Save the file with a known name.

    Login to your admin. Change index.php or whatever file is displayed at the end of the url to the filename just created and access the file. You will get a white page, but
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Mar 2006
    Posts
    477
    Plugin Contributions
    0

    Default Re: how to delete photos with SQL query?

    Quote Originally Posted by mc12345678 View Post
    How precisely do you know the image and path?

    You could create a php file, would suggest placing it in the admin so that it can't be accessed easily from the internet.

    Code:
    <?php
    require 'includes/application_top.php';
    
    if (!IS_ADMIN_FLAG) {
     die('Illegal Access');
    }
    
    $delete_photos = array(
    'path/file1',
    'path/file2',
    'path/file3'
    );
    
    foreach ($delete_photos as $photo) {
     unlink($photo);
    }
    Now, that assumes a full path.

    If your information is say based on being in the store's images directory, where you have say: attributes/prod1.jpg as the path, then:
    Code:
    unlink($photo);
    Could instead be:
    Code:
    unlink(DIR_FS_CATALOG_IMAGES . $photo);
    The generation of the array list should be relatively easy. Paste all of the paths, one per line. Add an apostrophe/single quote at the beginning of each. Add an apostrophe and comma at the end of each (may need to delete the last comma). Save the file with a known name.

    Login to your admin. Change index.php or whatever file is displayed at the end of the url to the filename just created and access the file. You will get a white page, but
    Hmm i have no clue on where to start with creating a PHP file.
    Ask for the file path we can just right click on the image and save the image address to that image.

    ill attempt this tomorrow when i have some time though and see if i can get that working.
    We sell ATV, Dirtbike, Streetbike, Snowmobile, Watercraft & Custom stickers & Banners. Check us out www.AD-DiscountPerformance.com

  9. #9
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,591
    Plugin Contributions
    30

    Default Re: how to delete photos with SQL query?

    I searched for obsolete images and then tried just images and went through 6 pages of downloads without finding something that seemed to do the reverse of the missing images plugin.
    I would have liked to add that to the missing images plugin, but I thought about it and it seemed like I would have to actually write new code so I decided to do some real work instead.
    So, there is no other mod out there that could be resurrected/updated to check for orphan images?
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  10. #10
    Join Date
    Aug 2014
    Location
    Lisbon
    Posts
    594
    Plugin Contributions
    0

    Default Re: how to delete photos with SQL query?

    Quote Originally Posted by torvista View Post
    I would have liked to add that to the missing images plugin, but I thought about it and it seemed like I would have to actually write new code so I decided to do some real work instead.
    So, there is no other mod out there that could be resurrected/updated to check for orphan images?
    Yesterday I've checked your plugin then I saw that for this purpose wouldn't do this job.
    But, how to know the images to delete ?
    Let's take a example of the banners, or attributes ( never use them, but I guess this images are also in the images folders), or something else.
    The "only" way, is to create some "exclude" folders... I guess...
    Else, if is not linked to a database product, will be deleted.

    Once I posted in code suggestions
    That or I'm seeing this wrong, or if one uploads a image, and then cancels the edit, the image is not deleted.
    Over time, is very easy a lot of space occupied with this canceled posts images.
    Last edited by mesnitu; 6 Feb 2019 at 12:45 PM.
    “Though the problems of the world are increasingly complex, the solutions remain embarrassingly simple.” ― Bill Mollison

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 9
    Last Post: 12 Jul 2023, 12:26 AM
  2. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  3. Delete Old Order IDs 1 to 3369 Using SQL Query
    By limelites in forum General Questions
    Replies: 1
    Last Post: 12 Apr 2013, 02:29 PM
  4. SQL Query to Delete All Products Only
    By toussi in forum General Questions
    Replies: 0
    Last Post: 26 Nov 2008, 06:57 PM
  5. How would I do this with an sql query?
    By member in forum General Questions
    Replies: 2
    Last Post: 22 Mar 2008, 05:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR