1
A
回答
4
$image_url = 'http://example.com/image.jpg';
$image = file_get_contents($image_url);
file_put_contents('/my/path/image.jpg', $image);
在坚果壳,抓形象,店面形象..那么容易。
注意:allow_url_fopen php.ini设置必须设置为true,才能使上述示例正常工作。
2
还有的曾经简单的方法:
$img = 'http://www.domain.com/image.jpg';
$img = imagecreatefromjpeg($img);
$path = '/local/absolute/path/images/';
imagejpeg($img, $path);
关于于allow_url_fopen上述评论也正因为这个方法也是如此。如果你有一个相当严格的主机,你可能需要利用卷曲来解决这个问题:
/**
* For when allow_url_fopen is closed.
*
* @param string $img The web url to the image you wish to dl
* @param string $fullpath The local absolute path where you want to save the img
*/
function save_image($img, $fullpath) {
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$binary_img = curl_exec($ch);
curl_close ($ch);
if (file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath, 'x');
fwrite($fp, $binary_img);
fclose($fp);
}
+0
您建议的第一种方法涉及比简单复制图像更多的开销。 – 2009-10-19 23:21:11
+0
唉,它可以让你用一些GD欺骗来操纵图像。 – 2009-10-19 23:51:19
相关问题
- 1. MySQL使用超链接存储图像
- 2. 在PHP中存储图像
- 3. 图像从链接图像中显示?
- 4. Firebase数据库表格链接到Firebase存储中的图像
- 5. PHP中存储的图像的URL
- 6. 功能404中的PHP图像链接
- 7. php图像存储 - 安全
- 8. Laravel 5.4从没有符号链接的存储中显示图像
- 9. 在PHP中识别图像链接
- 10. 从链接检索图像
- 11. 从存储的png中加载图像
- 12. 从html链接的Azure存储下载
- 13. 从webservice存储图像
- 14. 在PHP中从Google Drive链接中获取图像
- 15. PHP的图像符号链接
- 16. CKEditor中的图像链接
- 17. 链接Django中的图像
- 18. 从链接中删除图像CSS
- 19. 从链接中获取大小图像
- 20. 谷歌云存储图像公共链接到img src
- 21. 通过云端功能检索Firebase存储图像链接
- 22. 使用php存储/从数据库中提取图像
- 23. 从宝石获取存储库链接?
- 24. 存储图像
- 25. 存储图像
- 26. 图像解除链接在PHP
- 27. 图像链接在PHP函数
- 28. PHP嵌入html图像作为链接
- 29. 图像链接与功能在PHP
- 30. Azure - 将图像存储在存储帐户中,并将它们链接到表中的记录
是的,这将工作,假设allow_url_fopen设置在php.ini中。如果不是,则必须使用CURL来获取图像,然后使用file_put_contents()写入图像。 – BraedenP 2009-10-19 22:35:30
按照您的意见进行编辑:p – 2009-10-19 22:42:05
非常感谢,效果很好 – 2009-10-19 22:48:44