嘿伙计们,我正在寻找帮助从我的某个供应商处下载1000多张图片以获取电子商务网站的帮助。他们为我提供了我在数组中设置的正确URL,但我似乎无法获得我在功能上下载图像的任何PHP脚本。
我有:
ArrayOf1000ULRS[];
Loop through Array
-save_image(URL)
我在网上找到的功能示例:
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);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
答案 0 :(得分:0)
foreach($fileNames as $url)
{
set_time_limit(0);
//Get the filename from the end of the URL.
$imgName = explode("/", $url);
//Used this to run multiple scripts.
//Basically don't download files you have.
if(!file_exists("./images/".$imgName[-int-]))
{
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("./images/".$imgName[-int-],'w');
fwrite($fp, $rawdata);
fclose($fp);
}
}
答案 1 :(得分:-1)
假设你在* nix机器上,你可以在那里抛出一个系统调用并使用WGET。
foreach($arrayOfImages as $url){
$cmd = "wget $url";
system($cmd);
}
不安全,但如果这是一次性私事,我说要做。