我真的不懂任何 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 (使用 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;
关于php - 返回 php 文件中图像的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4494704/