-1

こんにちは、私のベンダーの 1 つから e コマース サイト用に 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);
}
4

2 に答える 2

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);
}
}
于 2012-10-12T15:39:58.230 に答える
-1

* nixマシンを使用していると仮定すると、そこにシステムコールをスローして、WGETを使用できます。

foreach($arrayOfImages as $url){
    $cmd = "wget $url";
    system($cmd);
}

一体としては安全ではありませんが、これが1回限りの個人的なことである場合は、それを実行してください。

于 2012-10-11T18:53:28.923 に答える