justinbeeler Posted March 18, 2010 Share Posted March 18, 2010 I have built a social networking site that allows members to upload their photos. I'm running Apache on Linux through Fatcow. I created a script that displays the thumbnail images and does just fine for .jpg, .jpeg, .png and .gif. But if someone uploads a file that has the .JPG extension, it doesn't display. I read somewhere that Apache treats .JPG differently from .jpg. So I changed the extensions on all of the files and changed them in the database too and that didn't fix it. So there must be something embedded in .JPG that apache recognizes and doesn't care about the extension being .jpg even if you change it. Does this make sense? Here is the script that loads the image, resizes and crops it: <?php include("config.php"); $fileName = $_GET['file']; $maxSize = $_GET['size']; $URL = $basePath . "/images/players/" . $fileName; $info = getimagesize($URL); $mime = image_type_to_mime_type($info[2]); header("Content-type: $mime"); // create an image resource $t_w = 100; $t_h = 100; switch($info[2]) { case IMAGETYPE_GIF: $src_image = imagecreatefromgif($URL); break; case IMAGETYPE_JPEG: $src_image = imagecreatefromjpeg($URL); break; case IMAGETYPE_PNG: $src_image = imagecreatefrompng($URL); break; } // store the width and height values of the image $orig_h = imagesy($src_image); $orig_w = imagesx($src_image); // test dimensions of image resource and set thumbnail width height to maintain correct aspect ratio if($orig_w > $orig_h){ $thumb_w = $maxSize; $thumb_h = $orig_h * ($maxSize / $orig_w); } if($orig_w < $orig_h){ $thumb_h = $maxSize; $thumb_w = $orig_w * ($maxSize / $orig_h); } if($orig_w == $orig_h){ $thumb_w = $maxSize; $thumb_h = $maxSize; } $x_mid = $thumb_w/2; $y_mid = $thumb_h/2; $dst_image = imagecreatetruecolor($thumb_w,$thumb_h); imagecopyresampled($dst_image,$src_image,0,0,($x_mid-($t_w/2)),($y_mid-($t_h/2)),$thumb_w,$thumb_h,$orig_w,$orig_h); switch($info[2]) { case IMAGETYPE_GIF: imagegif($dst_image); break; case IMAGETYPE_JPEG: imagejpeg($dst_image); break; case IMAGETYPE_PNG: imagepng($dst_image); break; } imagedestroy($dst_image); imagedestroy($src_img); ?> The way I use it on the page is like this: <img src="image_crop.php?file=filename.jpg&size=150" /> Can someone please help? Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/ Share on other sites More sharing options...
scvinodkumar Posted March 18, 2010 Share Posted March 18, 2010 could u please attach that image here, so that we can test it... Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028095 Share on other sites More sharing options...
justinbeeler Posted March 18, 2010 Author Share Posted March 18, 2010 Hey, thanks for jumping on this so quickly! Okay, I'm attaching an image that one of the members uploaded to the system. The page in question is here: http://gamectrl.com/?page=players Where the thumbnails are broken is where they had uploaded an image with the .JPG extension. I changed them like I said so if you use firebug or whatever to view the image source it says ".jpg" but still isn't working. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028099 Share on other sites More sharing options...
scvinodkumar Posted March 18, 2010 Share Posted March 18, 2010 i checked your image, its looks good, even i view this image in your site, its displaying correctly. not only this image, all images are displaying correctly. http://gamectrl.com/image_exact_crop.php?file=03.09.10-WSOP-Day-07-CFL-200.JPG&size=150 Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028102 Share on other sites More sharing options...
justinbeeler Posted March 18, 2010 Author Share Posted March 18, 2010 Did you go to the second page? Sorry, I should have been more specific. Here is a link to the second page: http://gamectrl.com/?page=players&p=2 There are two instances on that page where the thumbnails are not displaying. Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028108 Share on other sites More sharing options...
scvinodkumar Posted March 18, 2010 Share Posted March 18, 2010 i think two images has two different problem, for image Beaumontbg, there is problem with the filename, not JPG, its '&', so rename it and try for image bemot, the image may be broken. just check it Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028117 Share on other sites More sharing options...
justinbeeler Posted March 18, 2010 Author Share Posted March 18, 2010 I realize there are some unacceptable characters in the filenames, but the common thread in all of the broken images is that they all were uploaded to the system with capital .JPG extensions. I changed them so you won't be able to tell, but every single broken image had the exact same capital .JPG extension. I just wonder why php isn't treating .JPG the same way as .jpg and .jpeg since the MIME type should be the same, correct? Do you know if there is a fix through Apache .htaccess or a mod_rewrite or something? There are approximately 20 pages of thumbnails (I know the pages aren't labeled, haven't gotten there yet) and there are lots of instances of broken images. All of them I'm convinced are because they were originally .JPG. Thanks for looking it over by the way. Link to comment https://forums.phpfreaks.com/topic/195684-image-files-with-jpg-extension-not-displaying/#findComment-1028129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.