Download file from URL using CURL

后端 未结 3 1218
一整个雨季
一整个雨季 2020-12-16 02:28

I try to download file using a php-script from an URL like the following:

http://www.xcontest.org/track.php?t=2avxjsv1.igc

The code I use l

3条回答
  •  我在风中等你
    2020-12-16 03:16

    I had some issues making the (File Download Dialog Box) show up when using Curl until i did this :

    // $ch = curl_init();
    // curl_setopt($ch, CURLOPT_URL, $url); 
    // Other Curl options ....
    $output = curl_exec($ch);
    if (isset($_POST["downloadExcelFile"])){ 
            // in my code the "downloadExcelFile" field
            // is sent when i'm trying to download an excel file
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename="file.xls"');
            header('Cache-Control: max-age=0');
            $fp = fopen("php://output", 'w');
            fwrite($fp, $output );
            fclose($fp);
        }
    

提交回复
热议问题