Question

I have a very simple PHP script which creates "favicon.ico" form jpg/gif/png uploaded file.

Here is a part of function:

$file = 'cache/'.$e .'/'. basename($_FILES['uploadfile']['name']);

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {  

$im = imagecreatefromjpeg($file);
    list($width, $height) = getimagesize($file);
    $image_p = imagecreatetruecolor("16", "16");
    imagecopyresampled($image_p, $im, 0, 0, 0, 0, "16", "16", $width, $height);
    $num = rand (1,99999);
    $output = $num."-favicon.ico";
    imagepng($image_p,'dl/'.$output);
    imagedestroy ($im);
    unlink ($file);
    echo 'success';  

} 

And script works fine! In Chrome, Opera and Firefox generated favicon displays good, as it should do.

But in Interent Explorer 8 - it simply doesn't show up.

Thank you for any help!

Was it helpful?

Solution

You can't just save it as a PNG with the ico extension... I'm guessing Chrome/Opera/Firefox can't read the file, so they decide to open up the file and find out what the actual format is rather than depending on the file extension, while IE doesn't.

However, you will need to find a different solution to save it as an ICO as GD can't do that on its own, you can either try ImageMagick or after a quick Google phpThumb seems to be able to do it (not tried).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top