Solved

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

Posted on 2014-03-19
5
278 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 110

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 110

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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