PHP 多个远程图片打包下载

不多比比。

open($tmpFile, ZipArchive::CREATE);
foreach ($files as $file) {
    // download file
    // $fileContent = file_get_contents($file);

    $ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 0); 
	curl_setopt($ch,CURLOPT_URL,$file); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	$fileContent = curl_exec($ch);
	curl_close($ch);

    $zip->addFromString(basename($file), $fileContent);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=file.zip');
header('Content-Length: ' . filesize($tmpFile));
readfile($tmpFile);

unlink($tmpFile);
 

?>

 

你可能感兴趣的:(PHP 多个远程图片打包下载)