我正在使用fopen和fwrite下载远程网址。一个工作正常,但是当我使用多个网址时,只会下载第一个。
foreach($urls as $url) {
$filename = $core->getFileDestination($url);
$urlsize = $core->getUrlFileSize($url);
if (isset($_POST['downloaded'])){
$fileSize = filesize($filename);
$newfsize = $core->formatSize($fileSize);
$newurlsize = $core->formatSize($urlsize);
echo $filename." - ".$newfsize." / ".$newurlsize."<br>";
}
else{
$file = fopen ($url, "rb");
if ($file) {
$newf = fopen ($filename, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
echo "done";
}
}