Fix Issues Image Cron Script

Fix issues image cron script

We have an image cron script made in PHP which saves images from image-urls in the MySQLdatabase. There are some issues which I would like to have solved asap. Here is what the script does exactly:

1. Download the images of all products from table ‘affiliSt_products1′, column ‘prodImageURL’. An image can be in GIF or in JPEG format.
1a. If the image already exists, don’t download it -> Go to point 5 (Change the old URLs…)
1b. If the image doesn’t exist, download it -> Go to point 2 (Save them…)

2. Save them in the directory ‘/afbeeldingen/origineel’ and use the productname (column ‘prodName’) + productID of the merchant (column ‘merchantProdID’) as filename. Recplace spaces in the filename with ‘+‘ and the last space before the productID with ‘-‘. So for example a filename could be Van+der+valk+hotel+Assen-12345.jpg.

3. Resize the images in 2 formats, one which has a width of 180px and one which has a width of 250px. The image size is adjustable.

4. Save the 180px images in the directory ‘/afbeeldingen/klein’ , save the 250px images in the directory ‘/afbeeldingen/groot’. This size is also adjustable.

5. Change the old URLs of the images in the database to the new ones. Update the URLs of the 250px images in column ‘prodImageURL’ and the 180px images in ‘prodImageSmall’.

The script works almost fine, however there are a few issues that need to be solved:

1. On a local server the script works, on my new server online (CentOS, PHP 5.2.3) it gives this error: “Notice: Undefined index: TOTAL_IMAGES in xxxx/includes/get_image.php on line 58”

2. When I start the script with empty local image folders, it should download all images. However the script says that 39 images are already saved and it skips them. There are 39 products of the merchant ‘Fletcher’ in the database. I assume something goes wrong here.

3. If there’s a ‘strange’ character in the productname like “é,â,ä,à,å,ç,ë, etc..” the image is saved with a name like this D%FCsseldorf… and then the image can’t be loaded on the webpage. This should be solved.

4. There are some GIF images which are 375 bytes in sizes and black. I think this is caused by point 3 (strange characters) but am not sure.

5. Every night the products are refreshed in the database. So all the image-urls are set back and this image script has to run again. In this case the images already exist (they’re downloaded before). The script then detects the images already exist but it doesn’t set the image-urls to the new urls. (point 1a, it should go to point 5).

I hope this is clear, if not please let me know.

Leave a Reply

Your email address will not be published.