Author Topic: Image files with .JPG extension not displaying  (Read 503 times)

0 Members and 1 Guest are viewing this topic.

Offline justinbeelerTopic starter

  • Irregular
  • Posts: 5
  • Gender: Male
  • I'm a freelance graphic artist and web devigner
    • View Profile
    • Justin Beeler Freelance Graphic Artist
Image files with .JPG extension not displaying
« on: March 18, 2010, 09:53:15 AM »
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:
Code: [Select]
<img src="image_crop.php?file=filename.jpg&size=150" />

Can someone please help?
<a href="http://justinbeeler.com/jblog">This is my blog</a>

Offline scvinodkumar

  • Enthusiast
  • Posts: 209
  • Gender: Male
  • PHP Web Developer
    • View Profile
    • Web Collection
Re: Image files with .JPG extension not displaying
« Reply #1 on: March 18, 2010, 10:00:24 AM »
could u please attach that image here, so that we can test it...

Offline justinbeelerTopic starter

  • Irregular
  • Posts: 5
  • Gender: Male
  • I'm a freelance graphic artist and web devigner
    • View Profile
    • Justin Beeler Freelance Graphic Artist
Re: Image files with .JPG extension not displaying
« Reply #2 on: March 18, 2010, 10:11:59 AM »
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]
<a href="http://justinbeeler.com/jblog">This is my blog</a>

Offline scvinodkumar

  • Enthusiast
  • Posts: 209
  • Gender: Male
  • PHP Web Developer
    • View Profile
    • Web Collection
Re: Image files with .JPG extension not displaying
« Reply #3 on: March 18, 2010, 10:22:37 AM »
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.

Code: [Select]
http://gamectrl.com/image_exact_crop.php?file=03.09.10-WSOP-Day-07-CFL-200.JPG&size=150

Offline justinbeelerTopic starter

  • Irregular
  • Posts: 5
  • Gender: Male
  • I'm a freelance graphic artist and web devigner
    • View Profile
    • Justin Beeler Freelance Graphic Artist
Re: Image files with .JPG extension not displaying
« Reply #4 on: March 18, 2010, 10:32:46 AM »
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.

<a href="http://justinbeeler.com/jblog">This is my blog</a>

Offline scvinodkumar

  • Enthusiast
  • Posts: 209
  • Gender: Male
  • PHP Web Developer
    • View Profile
    • Web Collection
Re: Image files with .JPG extension not displaying
« Reply #5 on: March 18, 2010, 10:48:09 AM »
i think two images has two different problem,

for image Beaumontbg, there is problem with the filename, not JPG, its '&amp;', so rename it and try
for image bemot, the image may be broken.

just check it


Offline justinbeelerTopic starter

  • Irregular
  • Posts: 5
  • Gender: Male
  • I'm a freelance graphic artist and web devigner
    • View Profile
    • Justin Beeler Freelance Graphic Artist
Re: Image files with .JPG extension not displaying
« Reply #6 on: March 18, 2010, 11:07:42 AM »
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.
<a href="http://justinbeeler.com/jblog">This is my blog</a>