dongxian3418 2019-08-15 01:20
浏览 207

使用PHP从远程服务器下载多个pdf

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效