我无法制作一个能够复制远程图像并将其保存到目录的php文件。图像远程上传脚本
所以我要输入一组图像网址到第一个文本框中,当运行图像时会抓取这些图像并将它们保存到指定的目录并显示新的网址集。 :)
我该怎么做?
我无法制作一个能够复制远程图像并将其保存到目录的php文件。图像远程上传脚本
所以我要输入一组图像网址到第一个文本框中,当运行图像时会抓取这些图像并将它们保存到指定的目录并显示新的网址集。 :)
我该怎么做?
将此代码放在您的script.php
<?php
$image = 'http://remote.com/image.jpeg';
file_put_contents(dirname(__FILE__).'/'.basename($image), file_get_contents('http://remote.com/image.jpeg'));
顺便说一句,我做不知道任何关于PHP,我将如何插入这些代码?我想使用它,所以我可以访问脚本通过访问http://site.xx/script.php – Hillsid3 2011-03-04 11:54:53
我会用file_get_contents()
与fopen()
,fwrite()
,并fclose()
这帮开始。
<?php
foreach($_POST['image'] as $image) {
$f = fopen("/path/to/image/folder/".basename($image)); //Open image file
fwrite($f, file_get_contents($image)); //Write the contents of the web image to the newly created image on your server
fclose($f); //Close the file
}
?>
顺便说一句,我不知道任何关于PHP,我将如何插入这些代码?我想使用它,所以我可以通过访问http://site.xx/script.php来访问脚本 – Hillsid3 2011-03-04 11:55:22
这应该您开始使用
header("Content-Type: image/jpeg");
echo file_get_contents("http://www.somewebsite.com/images/image.jpg");
然后,您可以将该文件保存到本地目录
BTW,我不知道任何PHP,我将如何插入这些代码? – Hillsid3 2011-03-04 11:54:07
好的,然后检查在stackoverflow上的常见问题或搜索“PHP教程” – powtac 2011-03-04 11:58:25
这是一个不安全的做法,人们可以很容易地将代码放入图像,使其充当php,jsp,js等。 – 2011-11-16 17:15:06