dscc90150010 2017-02-14 18:57
浏览 75
已采纳

PHP - 使用URL读取图像

Here my problem, I do a query to MySQL (PDO) for give me the last 5 URLs of a table nammed avatar who contains the ID and the URL :

$response = $dbh->query("SELECT url FROM avatar ORDER BY id_URL DESC LIMIT 0,5 ");

And I did :

  while ($donnees = $response->fetch())
{

$urlImage = $donnees['url']; //'url' contains the URL
$result = file_get_contents($urlImage);        
header('Content-Type: image/png');
echo $result;   
?>

But the header just return a small empty white square. However, the "$result = file_get_contents($urlImage);" takes properly the URL because when I do :

   $urlImage = $donnees['url']; //'url' contains the URL
$result = file_get_contents($urlImage);        
echo $result;   
?>

It just shows the "encodage of the image" (a ton of special characters) but not displays the image.

I also try with "imagick" but it says to me that the class doesn't exist and I don't think that the imagecreatefrompng can be use with URL.

Thanks !

  • 写回答

2条回答 默认 最新

  • dotdx80642 2017-02-14 19:01
    关注

    If you're trying to use a dynamic image source where your url is the image source, and it isn't working, then the problem might be that there's a space or extra character somewhere on the page, which will make the browser treat it like a document instead of an image in some cases.

    Your problem is that the browser isn't understanding that it's supposed to be an image.

    You could always do:

    <img src="<?=$urlImage?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效