Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-03-19
5
276 Views
Last Modified: 2014-04-09
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
Comment
Question by:srikanth_saladi
  • 2
  • 2
5 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39939930
not working
Pretty sure that is not an error message, nor a symptom of failure.  Please tell us exactly what is happening, thanks.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 39940174
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
 

Author Comment

by:srikanth_saladi
ID: 39974642
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
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39974655
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
 

Author Closing Comment

by:srikanth_saladi
ID: 39988058
Yes,it worked out after renaming
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question