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

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?