Re: Problem Displaying Images in Firefox, Safari (Works in IE)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've had problems with images before and the issue was the file type.  In
FF, jpeg images show a file type of "image/jpeg" and in IE an uploaded jpeg
file image has a file type of "image/pjpeg",   So, if the FF browser won't
handle the MIME type of "image/pjpeg" then it won't show the image.

You may wish to do something like:

switch ($file_type){
    case "image/jpeg":
    case "image/pjpeg":
           header("content-type: image/jpeg");
           break;
    case "image/gif":
           header("content-type: image/gif");
           break;
     ..... etc.....
}

Then serve the file up.

On Mon, Mar 2, 2009 at 1:32 PM, HodgesC_Yah
<chodges@xxxxxxxxxxxxxxxxxxxxx>wrote:

>   Hello:
>
> Maybe someone can help me with this. I'm providing my site the
> ability to upload images. But the code I'm using will only display
> the images in IE. Firefox and Safari don't show anything. Anyone
> have any ideas why?
>
> function uploadTemp()
> {
> $uploaddir = getcwd()."/tmp_images/";
> $uploadfile = $uploaddir .
> basename($_FILES['uploadheadshot']['name']);
> move_uploaded_file($_FILES['uploadheadshot']['tmp_name'],
> $uploadfile);
>
> $fileName = $_FILES['uploadheadshot']['name'];
> $fileSize = $_FILES['uploadheadshot']['size'];
> $fileType = $_FILES['uploadheadshot']['type'];
>
> $fp = fopen($uploadfile, 'r');
> $content = fread($fp, filesize($uploadfile));
> fclose($fp);
>
> //Now before we return it lets resize it if necessary
> $ht = $_REQUEST["height"];
>
> if(strlen($ht) > 0)
> {
> $im = imagecreatefromstring($content);
> $width = imagesx($im);
> $height = imagesy($im);
>
> if((int)$height > (int)$ht)
> {
> // Set thumbnail-height to what as passed in
> $imgh = (int)$ht;
> // calculate thumbnail-height from given width to maintain
> aspect ratio
> $imgw = $width / $height * $imgh;
> // create new image using thumbnail-size
> $thumb=imagecreatetruecolor($imgw,$imgh);
> // copy original image to thumbnail
>
>
> imagecopyresampled($thumb,$im,0,0,0,0,$imgw,$imgh,ImageSX($im),ImageSY($im));
>
> header("Content-Type: {$fileType}");
> // Output the image
> imagejpeg($thumb,NULL,100);
> imagedestroy($thumb);
> return;
> }
> }
>
> if (!empty($content))
> {
> // Output the MIME header
> header("Content-Type: {$fileType}");
> // Output the image
> echo $content;
> }
> else
> {
> echo "<html><body>Error</body></html>";
> }
> }
>
>  
>


[Non-text portions of this message have been removed]


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux