我有一个php脚本,它从外部URL抓取图像,读取并保存到我的服务器上的目录中。该脚本位于一个PHP文件,包含:通过php在窗体中保存图像URL
<?php
$image_url = "http://example.com/image.jpg";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $image_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// Getting binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
$f = fopen('/home1/path/public_html/path/saved/image.jpg', 'w');
fwrite($f, $image);
fclose($f);
?>
一切的伟大工程有...
我希望做的是有剧本做了多个网址。 URL将以textarea形式写入,并以逗号(或其他)分隔。
然后提交按钮会告诉脚本使用表单中的所有URL来操作,并以任何名称保存,这并不重要(随机会很好)。
我还是一个新手,我正在学习PHP。
在此先感谢您的帮助!
编辑
我的代码看起来像现在这样:
<?php
error_reporting(E_ALL);
$image_urls = explode('\n', $_POST['urls']);
foreach ($image_urls as $image_url) {
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $image_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
$f = fopen('/home1/path/public_html/path/saved/'.rand().time().".jpg", 'w');
fwrite($f, $image);
fclose($f);
}
?>
它仅适用于第一个,并且不返回任何错误...任何想法?
感谢您的大力帮助!
存储个人网址在TXT或DB? – fabrik 2011-03-28 11:35:26
存储在textarea,除以行... – Charleshaa 2011-03-28 12:43:19
对不起,我完全忽略了这个问题。不知何故,我认为你想通过cron工作来获取这些图像。 – fabrik 2011-03-28 12:46:29