PHP批量下载图片

PHP代码如下:

    $zipname = tempnam('/tmp', '');
    $zip = new \ZipArchive();
    $zip->open($zipname, \ZipArchive::CREATE);

   $file_arr = ['url1','url2'];
    foreach ($file_arr as $item) {
        $data = http($item, 'GET', null, array(), true); 
        $file = iconv('utf-8', 'GBK', basename('图片名称.jpg'));
        $zip->addFromString($file, $data[1]); // $data[1]文件内容
    }

    $zip->close();

    header('Content-Type: application/zip;charset=utf8');
    header('Content-disposition: attachment; filename=批量下载.zip');
    header('Content-Length: ' . filesize($zipname));
    readfile($zipname);
    unlink($zipname);

你可能感兴趣的:(PHP批量下载图片)