Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从url显示图像并检索标题_Php_Image - Fatal编程技术网

Php 从url显示图像并检索标题

Php 从url显示图像并检索标题,php,image,Php,Image,我创建了一个返回随机图像的php函数 我使用图像/jpeg头直接将图像写入响应 为了跟踪返回的图像,我将在响应头中发送图像的ID。屏幕截图显示了详细信息。(请参阅标记的标题tryid) 现在,我需要在图像标签中显示此图像 <?php $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP headers with response curl_setopt($ch,

我创建了一个返回随机图像的php函数

我使用图像/jpeg头直接将图像写入响应

为了跟踪返回的图像,我将在响应头中发送图像的ID。屏幕截图显示了详细信息。(请参阅标记的标题tryid)

现在,我需要在图像标签中显示此图像

    <?php
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP headers with response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return the response rather than output it

    $resp = curl_exec($ch);

    ?>

    <img src='<?php echo $resp; ?>' />
如果我写这个

<img src='<?php echo $remote_url?>' />
”/>
然后我可以显示图像,但我还需要标题信息。

我尝试使用curl,以便既可以获取图像,也可以读取标题,但这段代码没有在图像标记中显示图像

    <?php
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 1); // return HTTP headers with response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return the response rather than output it

    $resp = curl_exec($ch);

    ?>

    <img src='<?php echo $resp; ?>' />

' />
总之,我试图在图像标签中显示图像,并读取请求头


我正在另一个屏幕截图中显示var_dump($resp)的输出。

您能显示
var_dump($resp)
的输出吗?@roberto06修改了我的问题以包含您请求的输出为什么不同时使用这两个解决方案?您可以只请求带有cURL的标题(使用
CURLOPT\u NOBODY
选项),还可以将您的图像URL与`.@roberto06热链接。每次我向远程URL发送请求时,它都会发送不同的图像。所以我可能不能同时使用curl和我理解。。。在你的卷曲回程中,你必须将头球与身体分开。试着看一看,我想可能对你有帮助。