Page 1 of 1

How to handle upper and lowercase Image extension(jpg/JPG) ?

Posted: Fri Jan 23, 2009 11:43 am
by divyadivya
Experts,

In the database the images are stored with jpg extension ; Where as they are stored as JPG on the server(where my php pages are).
For example :
In mysql database I have ; Image 1 = abc.jpg
On the server where my php pages are I have = abc.JPG

The image will not be displayed.

How to handle image extensions?

Here is the code for viewing images:

Code: Select all

 
 
<TR> 
 <TD WIDTH="180" STYLE="background-color:#B6DAF2;"><B>Image 1</B></TD>
  <TD><% if($i_row['image1'] && ! substr_count($i_row['image1'],'unavailable.')) { %><IMG
 BORDER="0" SRC="<%= '../files/' . $i_row['image1']; %>" ALT=" " WIDTH="300"><% } %></TD> 
//Files is where images are stored on server.$i_row[image1] is coming from database.
</TR> 
<TR>
 
 
 

Re: How to handle upper and lowercase Image extension(jpg/JPG) ?

Posted: Fri Jan 23, 2009 1:38 pm
by requinix
Make the database match the filenames, or the filenames match the database. Anything else is just a hack.

Re: How to handle upper and lowercase Image extension(jpg/JPG) ?

Posted: Fri Jan 23, 2009 1:39 pm
by califdon
As you have discovered, PHP is case sensitive when it comes to filenames, so you have to change them to be the same. I have always found it far simpler to enforce a simple rule about filenames: always use lowercase only. Period. Then you never have these problems. There are certainly other ways to handle it, but in my opinion you are just inviting continued problems if you don't simply enforce this rule.