Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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_Url - Fatal编程技术网

如何在php中通过url获取图像的内容?

如何在php中通过url获取图像的内容?,php,image,url,Php,Image,Url,我正在使用一个SNS网站的api,它正在上传一张图片。此api有一个参数“photo=photo\u file\u content”,它基于 现在我有了某个图像的url,但我不知道如何获取图像,我使用了$param['photo']=file\u get\u contents($pic\u path),但它不工作 那么,获得图像的正确方法是什么?谢谢。您可以使用。这是你最好的解决方案 此外,请尝试以下方法: $ch = curl_init ($url); curl_setopt(

我正在使用一个SNS网站的api,它正在上传一张图片。此api有一个参数“photo=photo\u file\u content”,它基于

现在我有了某个图像的url,但我不知道如何获取图像,我使用了
$param['photo']=file\u get\u contents($pic\u path),但它不工作

那么,获得图像的正确方法是什么?谢谢。

您可以使用。这是你最好的解决方案

此外,请尝试以下方法:

$ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        $gm=curl_exec($ch);
        curl_close ($ch);

并将结果
$gm
保存在一个文件中。

您确定您真的需要图像的内容吗?@NirmalRam Hi,Nirmal。api url为“”并带有POST方法。参数是“photo=photo\u file\u content&text=…&callback=…”,因此如果没有图像的内容,我如何将这些参数发布到api?谢谢。你是想用
curl
上传图像吗?在键入图像时,你用了我的话@Barmar:-)
文件获取内容
就足够了。将该图像发布到API的正确方式是什么?