Home > Open-Source Development, Web Development Software > osCommerce Tweak (Part I): Renaming Uploaded Images

osCommerce Tweak (Part I): Renaming Uploaded Images

January 10th, 2007

osCommerce is a fully featured open-source (free) online shop which can be downloaded from www.oscommerce.com. While it’s abundant with features there are a few tweaks that should be done before launching your e-commerce website. This first part describes how to automatically rename all uploaded images to prevent images being overwritten.

When you upload a product, category, or manufacturer image you will notice that the filename remains the same. This can lead to problems when uploading a different image with the same name, as this image will overwrite the previous one - therefore we must make the images unique.

This is done in one very quick and easy step. Firstly, open the following file in your text-based editor:

/admin/includes/classes/upload.php

Locate the following code (around line 70):

$this->set_filename($file['name']);

Replace with the following code:

$this->set_filename(time().$file['name']);

Upload this file again and add an image from the admin area. You will now see a 10-digit number appended to the start of the image. This number is a UNIX timestamp and is the number of seconds since 1970. This means that every image you upload will be unique.

For help on using or installing osCommerce please contact us on +44(0)1202 315285 or info@acmultimedia.co.uk. Learn more about AC Multimedia.

Further Information

Bookmark and Share

Open-Source Development, Web Development Software

  1. twb
    January 14th, 2010 at 21:27 | #1

    Thanks. For this was looking for a way to randomise (randomize?) filenames on upload! Lifesaver. Cheers :)

  2. keith
    May 13th, 2010 at 18:21 | #2

    great tip, thank you!

  3. October 25th, 2010 at 07:39 | #3

    Simple but effective solution

  1. No trackbacks yet.