0

Rename product images during upload

multimixer | work | Thursday October 16 2014

By default all product images that you upload via your administration panel go to folder /catalog/images/ with their original filename.

What is the result

  • The /images/ folder will soon become very unorganised. Product images will be mixed with any other images. Well, ok, you could say “who cares”. Trust me, there are cases where you’ll be happy to have them all in one folder within the images folder, so you can quickly zip them all together. For example, if you are moving your website to a new osCommerce version, here you want to keep only the product images. How to identify them if they are mixed up with anything you uploaded over the years?
  • It often happens that the filenames of your images are not valid filenames. For example, “big yellow (13).fo..jpg”. This may work fine on your computer, but will cause you issues if you try to share this product on Facebook. I recently had such an issue
  • It could also happen when uploading  a new image for a new product, that this filename already exist on your server. For example, product Lemon use image 1111.jpg that show a nice lemon, a year later you create product Melon and upload image 1111.jpg, that show this time a nice melon. The second file will overwrite the first one, so, both products, the lemon and the melon will show the melon image. No lemon image anymore :-(

Knowing the problems, we also know what we need

  • We need all images in a special images/products/ folder on the server
  • We need all images to have unique filenames on the server
  • We want the image name to be related to the product in some way

So, I did a modification that does exactly this: All product images are renamed during upload into following format

img_[products_id]_[image_id].extension

For example, for a product with id 25,

  • the first uploaded image, the “main image” would be like img_25.jpg.
  • The first additional image will be img_25_1.jpg
  • The next one img_25_2.jpg, and so on

All images go to a new folder catalog/images/products/

This is how things look like

Doesn’t this look much nicer and cleaner? All images have valid and unique filenames, you can easily find out what product they belong to, you have them all in one folder

The modification does not really affect the core code, since it require only 2 additions to a single file, it work on all osCommerce versions of series 2.3, from 2.3 up to 2.3.4. Feel free to get in touch if you want to have that on your store

UPDATE
The modification has been updated, allowing now SEO friendly image names, please check here

Click +1 to recommend this to your friends when they search.
Tags: ,

multimixer

follow multimixer on Twitter

Follow me on twitter. I'm not tweeting all day long and guaranteed no spam and no advertising.

If you like what you read and if you think it will help you in your online business, then please consider a donation.

There is no obligation to do so and all information provided here is free to use.

It will however help to keep this blog alive, free of advertising and full of content.

Comments are closed.