簡體   English   中英

PHP下載文件從下載文件的鏈接

[英]Php download file from link that downloads file

我正在嘗試使用php下載在調用URL時創建和下載的文件。

在這種情況下,我嘗試以編程方式從荷蘭氣象局下載txt文件,但是可以轉到以下網址(在此示例中)為http://projects.knmi.nl/klimatologie/daggegevens/getdata_dag.cgi嗎? lang = nl&byear = 2016&bmonth = 6&bday = 20&eyear = 2016&emonth = 6&eday = 22&variabele = FHX&variabele = FXX&variabele = TG&variabele = TN&variabele = TX&stations = 249&submit =下載+數據+集

轉到該URL將下載文件。

我想用php做到這一點,所以我可以使用文件的內容制作自定義圖表。

有誰知道如何用PHP做到這一點?

使用file_get_contents(): http//php.net/manual/en/function.file-get-contents.php

或使用CURL函數: http : //php.net/manual/en/function.curl-exec.php

編輯:CURL解決方案:

$url = 'http://projects.knmi.nl/klimatologie/daggegevens/getdata_dag.cgi?lang=nl&byear=2016&bmonth=6&bday=20&eyear=2016&emonth=6&eday=22&variabele=FHX&variabele=FXX&variabele=TG&variabele=TN&variabele=TX&stations=249&submit=Download+data+set';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$str = curl_exec($curl);

嘗試:

$content = file_get_contents("The URL here");
echo $content;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM