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

标签 php image

我真的不懂任何 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/

相关文章:

javascript - 是否可以将图像文件合并到一个 blob 中

python - 将二进制图像划分为 4x4 Python 并计算像素

css - 在表格类中设置 CSS 图像背景时出现问题

android - Phonegap 插件 :How to convert Base64 String to a PNG image in Android

Php按键排序多维数组

php - CSS 规则不适用于 PHP 而{

php - Div刷新和滚动条问题

php - 解码 php mysql 中的编码值

php - 在函数内创建新类或将其作为 PHP 中的参数传递更快吗

c# - Xamarin 表格 : Left Side Outline Border on image