Jump to content

Recommended Posts

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

 

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)";
}

 

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.