从php中的URL下载图像


Downloading image from URL in php?

我正在使用php从url下载图像。这是我的代码

$filenameIn = $_POST['url'];
$contentOrFalseOnFailure = file_get_contents($filenameIn);

$byteCountOrFalseOnFailure = file_put_contents($filenameOut, $contentOrFalseOnFailure);

它运行良好。现在的问题是,我的图像url在我的实时服务器上,例如网站名称为www.umair.com,图像地址为www.umair.com/image.jpg,现在file_get_contents($filenameIn)不起作用。

错误为:

警告:file_get_contents(www.umair.com/image.jpg):无法打开流:中没有这样的文件或目录

图像地址为www.umair.com/image.jpg

不,它不是,它是http://www.umair.com/image.jpg。而且,如果这不起作用(对于http://),那么您就不能启用fopen URL包装器。

尝试使用Web服务器的完整路径名。(即:http://www.umair.com)。

请注意此处的示例#1:http://php.net/manual/en/function.file-get-contents.php

此外,请查看用于打开URL的运行时配置:http://php.net/manual/en/filesystem.configuration.php