doujiu8479 2015-02-11 18:16
浏览 84
已采纳

PHP imagejpeg()无法在Opera中运行

I am using the following code to dynamically generate a background image:

$image = imagecreatefromjpeg( 'FILENAME' );
header( 'Content-Type: image/jpeg' );
imagejpeg( $image );

Opera displays nothing when I try to view this script. Chrome and IE work fine, and if I add header( 'Content-Disposition: attachment; filename=download.jpg' ); Opera will download the image as expected (and the content is correct).

Is there a workaround for this, or some header that I am not setting? I am surprised that Chrome handles the image correctly, while Opera (Chromium-based) does not.

Update: the same problem is true if I use, e.g., Content-Type: image/png and imagepng() instead: loads in all browsers but Opera, and Opera downloads the file correctly.

Update': this is an extension problem, but I don't know why. Adding my site to the whitelist of uBlock makes everything work. My site has practically zero traffic and certainly doesn't spam anything, so this is odd.

  • 写回答

3条回答 默认 最新

  • dongtanxi5676756 2015-02-11 19:52
    关注

    In that case the cleaner solution would be just to put 'banner.php' in one of your images folder and put this in the .htaccess of the folder 'banner.php' is in:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}banner.php [NC,L]
    

    (provided you have mod_rewrite loaded in Apache)

    It checks if an image exists, if not it lets banner.php handle the job.

    That way you can just use "banner.jpg" as the source and neither Opera or anyone else will know it's dynamically generated..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启