【发布时间】:2016-10-04 13:24:30
【问题描述】:
我需要创建一个返回 JPEG 图像的 php 文件。 我写了这段代码,但它不起作用:
<?php
header('Content-type: image/jpeg;');
$p = 'http://....file.jpeg';
$a = file_get_contents('$p');
echo $a;
?>
怎么了?我觉得太简单了
【问题讨论】:
我需要创建一个返回 JPEG 图像的 php 文件。 我写了这段代码,但它不起作用:
<?php
header('Content-type: image/jpeg;');
$p = 'http://....file.jpeg';
$a = file_get_contents('$p');
echo $a;
?>
怎么了?我觉得太简单了
【问题讨论】:
去掉单引号:
<?php
header('Content-type: image/jpeg;');
$p = 'http://....file.jpeg';
$a = file_get_contents($p);
echo $a;
?>
【讨论】:
$p中放url,而是本地路径。 (如果那是你正在做的)。如果我们不知道错误是什么,就很难调试代码......
file_get_contents 的输出是什么?什么不工作?
您可以简单地使用<img> 标签。
<?php
$src = 'file.jpeg';
?>
<img src='<?php echo $src ?>'>
如果这不是您想要的功能,请查看如何Show image using file_get_contents。
【讨论】: