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条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题