douhuang9886 2011-09-04 04:19
浏览 47
已采纳

PHP GD - 为Internet Explorer创建favicon.ico

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!

  • 写回答

1条回答 默认 最新

  • douseda0009 2011-09-04 04:42
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题