• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

How to append .jpg extension for the images urls when there is no extension?

I am generating zoom, thumbnail, and preview images for some images. Some images are saved without their extension. When I am displaying in the image gallery, images without extension are not zooming. This is because the lightbox which we are using is expecting a .jpg extension for images. So the images are not zooming when clicking on it. Zooming on images with the extension are ok.

For this I am appending the .jpg extension like the code below, but it is not working.


<?php foreach($images as $line):
    $image_info = pathinfo($line['big']->filename);
    if(!array_key_exists('extension', $image_info))
    {
        $zoom_file = $line['big']->filename."?ext=.jpg";    
    }
    else 
    {
        $zoom_file = $line['big']->filename;
    }

?>

<li>
    <a href="<?php echo $media_cdn.$zoom_file?>"> 
        <img src="<?php echo $media_cdn.$line['normal']->filename ?>"
            width = "200px" alt="image" />
    </a>
</li>

<?php endforeach;?>

Open in new window

0
srikanth saladi
Asked:
srikanth saladi
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
not working
Pretty sure that is not an error message, nor a symptom of failure.  Please tell us exactly what is happening, thanks.
0
 
InsoftserviceCommented:
try this one

replace "testimg" with $line['big']->filename;

$src_file_name = "testimg";
$ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION)); // Using strtolower to overcome case sensitive

if( (trim($ext) == ""))
{
  $src_file_name = $src_file_name.".jpg";
}
echo $src_file_name;
0
 
srikanth saladiAuthor Commented:
Hi

insoftservice,


I have managed to do like the way you did in above comment,by adding jpg to the images if not there through code.But light box not opening even after appending .jpg to the image.We can open the image if there is no extension also.But light box expecting .jpg.

Even if we add .jpg,something needs to be done to the code,so that light box will open the image.
0
 
Ray PaseurCommented:
Have you renamed the image files (on disk, in the directory) so that they contain the correct suffix? If not, try that on an image and see if it helps.  You can test it by this process, assuming you have JPG image files:

1. Rename the file from something like "image" to "image.jpg"
2. Put the full image name (URL) into the HTML <img> tag to see if the browser can render the image.

As always, back up your files first!
0
 
srikanth saladiAuthor Commented:
Yes,it worked out after renaming
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now