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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
divyadivya
Forum Newbie
Posts: 1
Joined: Fri Jan 23, 2009 11:40 am

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

Post 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>
 
 
 
Last edited by divyadivya on Fri Jan 23, 2009 3:40 pm, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

Make the database match the filenames, or the filenames match the database. Anything else is just a hack.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
Post Reply