【问题标题】:php get image from urlphp从url获取图片
【发布时间】: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;
?>

怎么了?我觉得太简单了

【问题讨论】:

    标签: php image url


    【解决方案1】:

    去掉单引号:

    <?php
    header('Content-type: image/jpeg;');
    $p = 'http://....file.jpeg';
    $a = file_get_contents($p);
    echo $a;
    ?>
    

    【讨论】:

    • 还是不行。我必须设置任何文件权限吗?现在是 755
    • 它工作得很好。我刚检查过。那一定是其他不适用于您的情况。
    • 磁盘上有文件吗?然后不要在$p中放url,而是本地路径。 (如果那是你正在做的)。如果我们不知道错误是什么,就很难调试代码......
    • 文件进入服务器。如何检索任何错误?
    • file_get_contents 的输出是什么?什么不工作?
    【解决方案2】:

    您可以简单地使用&lt;img&gt; 标签。

     <?php 
        $src = 'file.jpeg';
     ?>
    
     <img src='<?php echo $src ?>'>
    

    如果这不是您想要的功能,请查看如何Show image using file_get_contents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 2010-11-16
      相关资源
      最近更新 更多