<?php
//Get the file
$content = 'http://dev.aviesta.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg ';
//Store in the filesystem.
$fp = fopen('/var/www/ajaxForm/loading.gif', 'w');
fwrite($fp, $content);
fclose($fp);
?>
当我尝试此操作时出现以下错误
Warning: fopen(/var/www/ajaxForm/loading.gif): failed to open stream: No such file or directory in /var/www/curlimage.php on line 5 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/curlimage.php on line 6 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/curlimage.php on line 7
最佳答案
$url = 'http://dev.aviesta.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg';
$img = 'curl/curl_image.jpg';
file_put_contents($img, file_get_contents($url));
注意:同时使用 is_writable检查目录是否可写方法
引用:
关于php - 通过php获取内容从url保存图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14191425/