Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-19
5
Medium Priority
?
280 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…
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)
Suggested Courses

636 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