加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

在php文件中返回图像的内容?

发布时间:2020-12-13 18:20:46 所属栏目:PHP教程 来源:网络整理
导读:我真的不知道任何 PHP,但我喜欢做一件简单的事情: 我从 img src =“/ myhumbleimage.php”/中访问一个php页面.我想从另一个URL返回一个图像. 我提出了: ?phpheader('Content-Type: image/png');readfile('i' . rand(1,3) . '.png');exit; 它有效: Avatar
我真的不知道任何 PHP,但我喜欢做一件简单的事情:
我从< img src =“/ myhumbleimage.php”/>中访问一个php页面.我想从另一个URL返回一个图像.

我提出了:

<?php
header('Content-Type: image/png');
readfile('i' . rand(1,3) . '.png');
exit;

它有效:
Avatar selection http://vercas.webuda.com/img.php?.png
(重新加载页面几次!)

查看 readfile().

基本思想是发送适当的MIME类型头(使用header()),然后使用readfile()传递文件内容.

例如

<?php
// myhumbleimage.php

// Do whatever myhumbleimage.php does before the image is delivered

header('Content-Type: image/jpeg');
readfile('path/or/url/of/image/file.jpg');
exit;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读