I have a page which displays images for products whose product IDs are stored in a database table.
The images are named by the product IDs.
I have constructed a basic CMS so that my client can upload product prices etc and she then uploads files using FTP software.

The problem is that often she uploads a mixture of images with .jpg and .JPG file extensions. Is it possible to get the <img> tag to accept either?

Recommended Answers

All 8 Replies

Member Avatar for diafol

Have you tried it?

Helen,

Case sensitivity of filenames is a server issue, and there's nothing you can do in the HTML other than use the right case for every filename you wish to your users to see.

Realistically, the measures you can take are twofold (and you should do both):

  1. Rename all the files on the server to be 100% consistent - I suggest all lower case. For a small number of files (tens), you can do this manually using your FTP software. For a larger quantity (hundred+) you might want to use automated means (eg. Linux/Unix's 'Cron' - I'm not an expert, maybe someone else can advise)
  2. For the future, get your client to set her FTP software up such that it converts filenames to lowercase on upload. I have used several FTP programs over the years and most have this facility built in. You need to look through the settings.

A possible third option (I mention it only to dismiss it) is to get the web server to override the server Operatiing System's case sensitivity. This is possible in Apache (and maybe other web servers) but typically not a setting that you can make yourself. The host will be unwilling to change the setting as there are performance considerations. (duly dismissed)

In conclusion, it's not all doom and gloom. Measures 1 and 2 above should see you right.

Hope this helps

Airshow

Thanks for such a clear reply.
Forcing the conversion filenames to lowercase sounds like a sensible idea. I usually use Filezilla, but couldn't see an option to do this.
Could you recommend any other ftp that has this facility. Preferably free ones, as I would be recommending it to my client.

WinSCP is a good one.

Well, I was thinking more along the lines of .htaccess. You could add a mimetype decalring JPG as an image. This as far as I know will work fine.

But it is a good idea to change them all. You could run a simple command on the upload script or can manually run a script post upload that will scan for all the .JPG files and change them to .jpg.

I think the upload version is much better and I would also advise image resizing. This will also speed up the page loading. For instance if the client was to upload a 1024x768 image that will take a very long time to load. If you resize it to at max a 90x90 then this will reduce the download time to virtually null.

Thanks Josh, I have downloaded WinSCP and this looks like a great option.
Resizing isn't proving a problem, the client is aware this has to be done.

Okay, well I tend to beleive in dynamic applications so I would advise making something that can do it via a click of a button.

Helen,

Well, I was thinking more along the lines of .htaccess. You could add a mimetype decalring JPG as an image. This as far as I know will work fine.

Adding a mime type may help but only if the image file names that appear in the HTML are case-identical to those on the server. Decalring JPG as an image will ensure that myimage.JPG will be served as an image but will not ovecome case incompatibility between <img src="myimage.jpg"> and file name = myimage.JPG .

More amusingly put, (under Linux/Unix) myimage.JPG is as different from myimage.jpg as it is from yourimage.gif !

Anyway, JC and I pretty well agree that you've got to get all the uploaded files into lower case, then use lower case with impunity in your HTML.

I use CuteFTP these days by the way but WinSCP looks like it might be good too.

Hope this helps.

Airshow

It does tend to crash but it's quite good and doesn't crash too often.

But yes change either the upload to make all the extensions lowercase or make a scrip that will scan or upercase versions and rename them.

Similarly gif and GIF do tend to do the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.