divadiva Posted January 23, 2009 Share Posted January 23, 2009 Experts , I am struggling with it for quite some time.I anyone can help me out of my misery ,I will appreciate that. How can I ignore the file extension.So that if in database the extension is JPG and in filesystem it is jpg .It should work. Database:abc.JPG Filesystem:abc.jpg.(All images are inside IMAGE folder ) The database is not consistent I am aware of it as well.Also,Changing option will screw up my website.As I have tried and it got screwed.Now I have fixed that. Here is my code for viewing image: <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> </TR> <TR> <TD WIDTH="180" STYLE="background-color:#B6DAF2;"><B>Image 2</B></TD> <TD><% if($i_row['image2'] && ! substr_count($i_row['image2'],'unavailable.')) { %><IMG BORDER="0" SRC="<%= '../files/' . $i_row['image2']; %>" ALT=" " WIDTH="300"><% } %></TD> </TR> <TR> Thankyou in advance. Best Regards, Divya Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/ Share on other sites More sharing options...
genericnumber1 Posted January 23, 2009 Share Posted January 23, 2009 It would be best to correct it in the database, as any php solutions would just be messy bandaids that could explode in the future (and no one likes exploding bandaids). Also, why are you using asp style tags? Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744594 Share on other sites More sharing options...
divadiva Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks for replying. Is there any other solution ? But I have not written this code I am modifying this code.Dont have the rightsto change it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744597 Share on other sites More sharing options...
Maq Posted January 23, 2009 Share Posted January 23, 2009 I don't think there's a way, unless they are all lower case extensions in the directory then you could just do strtolower(). The best but longest way would be changing the names to be consistent in the DB and server but if you can't touch it then we have to go a different route. You have to: -take the extension by exploding it by the dot. -do a strtoupper and string to lower on it -check if either the lower case or upper case exists in the directory -which ever one exists, display it. Example (from another forum): if(file_exists($housepicJPG)) { $thumbpiccode=""; $thumbJPG="(Found it)"; } elseif (file_exists($housepicJPG2)) { $thumbpiccode=""; $thumbJPG="(Found it)"; } Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744608 Share on other sites More sharing options...
divadiva Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks Maq!! I am going with what you all have suggested "be consistent with the database". Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744720 Share on other sites More sharing options...
Maq Posted January 23, 2009 Share Posted January 23, 2009 Wherever you it is being entered just do a trim() and strtolower() on it, along with the all the cleansing functions of course. Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744722 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 Well, you could do this: <?php function getImageName($name) { $name = pathinfo($name, PATHINFO_FILENAME); foreach (glob(strtolower($name)) as $name) { return $name; } return "Unable to find"; } ?> <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/' .getImageName($i_row['image1']); %>" ALT=" " WIDTH="300"><% } %></TD> </TR> <TR> <TD WIDTH="180" STYLE="background-color:#B6DAF2;"><B>Image 2</B></TD> <TD><% if($i_row['image2'] && ! substr_count($i_row['image2'],'unavailable.')) { %><IMG BORDER="0" SRC="<%= '../files/' . getImageName($i_row['image2']); %>" ALT=" " WIDTH="300"><% } %></TD> </TR> <TR> See if that will work for you. Quote Link to comment https://forums.phpfreaks.com/topic/142146-ignoring-the-file-extensionchallenging-one-for-me/#findComment-744736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.