Jump to content

[SOLVED] Create Thumbnails working on FF doesn't work on IE


Recommended Posts

Hi guys, i really confused why this code doesn't work on IE, i have tested on FF working fine.

 

code is:

<?php
if (isset($_FILES['slika']['name']) and $_FILES['slika']['name'] != ""){
	if (is_uploaded_file($_FILES['slika']['tmp_name'])) {
   $types = array(".jpeg", ".JPEG", ".jpg", ".JPG", ".gif", ".GIF", ".png", ".PNG");
   $ext = strtolower(strrchr($_FILES['slika']['name'], "."));
   $slika = strtolower($_FILES['slika']['name']);
   if (file_exists("../sliki/galerija/".$slika)){
  	$novo_ime = time();
  	$slika = $novo_ime . strtolower($_FILES['slika']['name']);
  }
  $slika_temp = $_FILES['slika']['tmp_name'];
  $mesto = "../sliki/galerija/".$slika;
if (in_array($ext, $types)) {
		 move_uploaded_file($slika_temp, $mesto);
  }
  $pat = $slika;
  $slika_org = "../sliki/galerija/". $slika;
  $snimi = "../sliki/galerija/slikicki/". $slika;
  list($width, $height) = getimagesize($slika_org);
   
    $sirina = 140;
  //$diff = $width / $sirina;
  $visina = 115; 
  if ($_FILES['slika']['type'] == "image/jpg" or $_FILES['slika']['type'] == "image/jpeg"){
   $tn = imagecreatetruecolor($sirina, $visina) ; 
     $image = imagecreatefromjpeg($slika_org) ; 
     imagecopyresampled($tn, $image, 0, 0, 0, 0, $sirina, $visina, $width, $height) ;                                         
     imagejpeg($tn, $snimi, 100) ;
    } else if($_FILES['slika']['type'] == ".gif" or $_FILES['slika']['type'] == ".gif"){
     $tn = imagecreatetruecolor($sirina, $visina) ; 
     $image = imagecreatefromgif($slika_org) ; 
     imagecopyresampled($tn, $image, 0, 0, 0, 0, $sirina, $visina, $width, $height) ;                                         
     imagegif($tn, $snimi, 100) ;
  }
  $slikicka = "slikicki/". $pat; 
   }
  } else {
$slika = "";
$slikicka = "";
}
?>

hi rhodesa, this is code for create thumbnails, but i have tested on FF working great, in IE cannot create only jpg thumbnail.

on gif i have changed code to:

<?php else if($_FILES['slika']['type'] == "image/gif"){ ?>

and now working on IE, only jpg, jpeg cannot create thumbnails.

Yeah, IE likes to upload JPEGs as "Progressive JPEGs" which have a content type of "image/pjpeg"...stupid, i know. to see the issue for yourself, and to debug this in the future, add an ELSE clause so it looks like:

     if ($_FILES['slika']['type'] == "image/jpg" or $_FILES['slika']['type'] == "image/jpeg"){
      $tn = imagecreatetruecolor($sirina, $visina) ; 
     $image = imagecreatefromjpeg($slika_org) ; 
     imagecopyresampled($tn, $image, 0, 0, 0, 0, $sirina, $visina, $width, $height) ;                                         
     imagejpeg($tn, $snimi, 100) ;
    } else if($_FILES['slika']['type'] == ".gif" or $_FILES['slika']['type'] == ".gif"){
     $tn = imagecreatetruecolor($sirina, $visina) ; 
     $image = imagecreatefromgif($slika_org) ; 
     imagecopyresampled($tn, $image, 0, 0, 0, 0, $sirina, $visina, $width, $height) ;                                         
     imagegif($tn, $snimi, 100) ;
     }else{
        die($_FILES['slika']['type'] . " is not a valid Content-Type");
     }

 

then, adjust your first if statement to have the new content type

Did you write this code?

 

if ($_FILES['slika']['type'] == "image/jpg" or $_FILES['slika']['type'] == "image/jpeg" or  $_FILES['slika']['type'] == "image/pjpeg"){

 

Well either way, this is how you fix it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.