Zen Cart Logo

Product image file name

Locked

Views: 1,688

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
28 May 2008, 10:10 PM
#1
knarf180 avatar

knarf180

New Zenner

Join Date:
May 2008
Posts:
4
Plugin Contributions:
0

Product image file name

It seems when you upload a product image it will save the image to the server using the images original file name.

Would it be possible to have zen cart assign the uploaded image a random file name so that you dont run into the problem of overwriting an image that belongs to a different product?

I've looked through the code for about an hour and cant seem to find where to even start correcting this. Has anyone already done it?

28 May 2008, 10:47 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Product image file name

You may want to look at Image Handler 2 to manage your product images.

Alternatively, you can choose not to overwrite an existing image when you select an image in product creation, so this should alert you to any impending problems.

28 May 2008, 11:11 PM
#3
knarf180 avatar

knarf180

New Zenner

Join Date:
May 2008
Posts:
4
Plugin Contributions:
0

Re: Product image file name

Isnt Image Handler 2 used for creating thumbnails? I dont think it cares much about file name.

As for the overwrite option, I have changed the default to no in the code. This is not exactly a fix however. I would prefer the filenames to either be random or be given an ID such as the item number to prevent any mistakes.

I find it odd that the system wasnt build this way in the first place.

28 May 2008, 11:24 PM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Product image file name

The system was built for people who knew what they were doing when giving names to images. Assigning random names or even the product id eliminates the possibility of owners using a system that is meaningful to them.
If an owner wants to update product images, a random or fixed naming system makes it impossible to easily tell which images are new or old.

28 May 2008, 11:31 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Product image file name

Another point is that for some sites, some products may share an image. Automatically assigned names eliminate this possibility and require a separate copy for each product.

However, having an option to automatically assign filenames when saving images would be a good thing for those who want it. A random name makes it impossible for humans to manage images manually; a name based on the product id would be short, unique and possible to manage.

29 May 2008, 12:05 AM
#6
knarf180 avatar

knarf180

New Zenner

Join Date:
May 2008
Posts:
4
Plugin Contributions:
0

Re: Product image file name

My problem is that the owner of the site isnt exactly computer literate. He just wants to be able to upload anything and not have to check if a file name exists first .

As for new and old images. Unless you need to keep an old image, not sure why you would, the new one would replace it.

In the case of multiple items sharing the same image, one product is the owner of the image and the others get the image file name pasted into the "select an existing image file from server" box.

29 May 2008, 1:42 AM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Product image file name

For your client's situation, I can see an auto-generated filename being useful.
In general, I don't like the idea of dumbing down the system to reduce operator flexibility.

There would be no way to tell if you had already replaced an image if the filename is forced to stay the same, and an automatic system would by definition rename or make a new copy of a file given to it. If you can bypass that, you no longer have a foolproof system.

At any rate, it would be a trivial matter in the product creation code to look up the current product's id and build the filename to use; changing the actual filename while saving it should be possible for one who knows the Zen Cart code and PHP thoroughly. Then the option of using an existing filename has to be eliminated, possibly while copying an existing file from the ZC folders. Finally, a switch in admin to turn this feature on & off might be a good thing.

29 May 2008, 2:11 AM
#8
knarf180 avatar

knarf180

New Zenner

Join Date:
May 2008
Posts:
4
Plugin Contributions:
0

Re: Product image file name

I've been reading the code. It seems that for a new product, the ID is not set until after the preview page however the image is saved to the folder before hand.

If this is the case, if you change your mind and press the back button on the preview page the image will be left on the server - I havent seen anything that goes back and deletes it yet. (untested)

Without a major rewrite, best the way of doing this would be to assign it a random name and then go back and change it after the ID has been set.

35% complete in coding it