使用PHP和Curl下载文件,而不知道文件的完整路径

时间:2018-06-14 20:37:51

标签: php file curl download

我需要一些有关以下问题的帮助。 我的php网页我需要从网上下载excel文件,但我没有文件路径,当我进入url链接时开始下载,例如:www.example.com/prices。 输入该URL,下载开始。 对此有何帮助? 我没有卷曲。任何帮助的代码?

//DESCARGA DE ARCHIVO
libxml_use_internal_errors(true);     
$url = "http://www.distribuidoraidem.com.ar/precios";
$filecontent = file_get_contents($url);
$tmpfname = tempnam(sys_get_temp_dir(),"tmpxls");
file_put_contents($tmpfname,$filecontent);

之前我使用curl在网上登录,所以如果你尝试代码将无法正常工作。 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作。

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'www.example.com/prices');
    $fp = fopen('prices.xlsx', 'w+');
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_exec ($ch);
    curl_close ($ch);
    fclose($fp);