im trying to download multiple pdfs with php. i get an array of urls which each brings a pdf file, this is what i've been doing:
function create_zip($datos, $institucion){
$save_to='pdfs/';
if (!file_exists('pdfs')) {
mkdir('pdfs', 0777, true);
}
$multiCurl = array();
$result = array();
$mh = curl_multi_init();
foreach ($datos as $i => $value)
{
var_dump($value->name . '-' . $value->consolidado);
echo '<br>';
$fetchURL = $value->consolidado;
$multiCurl[$i] = curl_init();
curl_setopt($multiCurl[$i], CURLOPT_URL,$fetchURL);
curl_setopt($multiCurl[$i], CURLOPT_HEADER,0);
curl_setopt($multiCurl[$i], CURLOPT_RETURNTRANSFER,1);
curl_setopt($multiCurl[$i], CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($multiCurl[$i], CURLOPT_SSL_VERIFYHOST, false);
curl_multi_add_handle($mh, $multiCurl[$i]);
}
$index=null;
do {
curl_multi_exec($mh,$index);
} while($index > 0);
foreach($multiCurl as $k => $ch) {
$result[$k] = curl_multi_getcontent($ch);
$archivo = fopen($save_to. $datos[$k]->name .'.pdf','w+');
fputs($archivo,$result[$k]);
fclose($archivo);
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
}
however when i execute that code i only get 1 pdf file that shows information the others are broken for some reason i cant figure out, any ideas whats happening? any help would be appreciated, btw i'm not trying to keep those pdf files in the server i wanna put them there so i can zip and download them later.