Solved

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

Posted on 2014-03-19
5
271 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 108

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 108

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 13
jQuery Canlendar click function 5 22
JavaScript Scope issue 4 20
ajax form sumbit 3 27
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now