Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 在html中显示来自curl请求的图像<;img>;标签_Php_Html_Curl_Php Curl - Fatal编程技术网

Php 在html中显示来自curl请求的图像<;img>;标签

Php 在html中显示来自curl请求的图像<;img>;标签,php,html,curl,php-curl,Php,Html,Curl,Php Curl,我正在工作的网站的一个页面应该显示有关漫画的信息,比如封面图片 我正在尝试显示通过发出卷曲请求得到的图像 <?php if(isset($_GET['info'])) { $postedData = $_GET["info"]; //json object containing info about manga such as author/title etc. $info = json_decode($postedData, true);

我正在工作的网站的一个页面应该显示有关漫画的信息,比如封面图片

我正在尝试显示通过发出卷曲请求得到的图像

<?php
    if(isset($_GET['info'])) {
        $postedData = $_GET["info"]; //json object containing info about manga such as author/title etc.
        $info = json_decode($postedData, true);
        $mangacoverid = $info['im']; //id of the cover image that i'm getting from json object

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://cdn.mangaeden.com/mangasimg/" . $mangacoverid); //link of API i'm using and adding cover id to it
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
        $picture = curl_exec($ch);
        curl_close($ch);
        header('Content-type: image/jpeg');
        echo $picture; //displays image in browser
    }
        ?>

我测试了您的代码,当封面ID硬编码时,它似乎工作正常。
问题可能是通过查询参数传递的JSON没有得到正确的解析(由于URL编码)

使用硬编码的封面ID时,它是否对您正常工作

文件
image.php


好的,我会发布解决方案,以防有人碰到这个问题

代码与原始代码基本相同:只编辑了几行,如下所示

-我在目录中创建了一个名为“tempcolve.jpg”的文件

-我使用函数'imagecreatefromstring($picture')获得了图像

-我用“imagejpeg($img,'tempcolver.jpg',100)”将图像保存到文件中

通过这样做,我可以引用HTML标记中的文件,并以我想要的方式显示它

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://cdn.mangaeden.com/mangasimg/" . $mangacoverid); //link of API i'm using and adding cover id to it
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $picture = curl_exec($ch);
    curl_close($ch);
    $img = imagecreatefromstring($picture);
    imagejpeg($img,'tempcover.jpg', 100);
    ?>

<!--HTML-->
    <img src="tempcover.jpg" alt="bruh" height="400px" width="300px">
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,”https://cdn.mangaeden.com/mangasimg/“$mangacoverid)//我正在使用的API链接,并向其添加封面id
curl_setopt($ch,CURLOPT_头,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_BINARYTRANSFER,1);
$picture=curl\u exec($ch);
卷曲关闭($ch);
$img=imagecreatefromstring($picture);
imagejpeg($img,'tempcolve.jpg',100);
?>

谢谢您的回复。url本身工作并返回了一个图像,但我想将该图像显示在html中的一个中,以引用文件中的图像。问题是,一个页面上只有一个图像显示在多个图像上。您可以将脚本重命名为“image.php”然后在输出HTML的脚本中,您可以执行
。对于我当前的目的,我只需要每页显示一个图像(即:阅读漫画时,我只需要显示当前章节)。你能解释一下你在第二条评论中的意思吗?:)问题是,如果两个不同的用户同时加载不同的页面,他们会得到错误的图像。这是一个幼稚的临时解决方案。有关正确的实施,请参阅已接受的答案。