在php文件中返回图像的内容? [英] Return the contents of an image in php file?

查看:168
本文介绍了在php文件中返回图像的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道任何PHP,但我喜欢做一件简单的事情:

我从< img src =/ myhumbleimage中访问一个php页面.php/> 我希望从另一个网址返回一张图片。

I really do not know any PHP but I'd love to do one simple thing:
I access a php page from within a <img src="/myhumbleimage.php" /> and I'd like to have an image returned from another URL.

我想出了:

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

它有效:

头像选择http://vercas.webuda.com/img.php?.png

(重新加载页面几次! )

And it works:
Avatar selection http://vercas.webuda.com/img.php?.png
(Reload the page a few times!)

推荐答案

查看 readfile()

基本思路是发送相应的MIME类型标题(使用header())然后使用<$传递文件内容c $ c> readfile()。

The basic idea is you send the appropriate MIME type headers (using header()) then deliver the file contents using 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;

这篇关于在php文件中返回图像的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆