开发者

How Do I Set PHP to Download File to a Specific Directory?

I am looking for some general guidance on this one...

I have created a PHP script that uses cURL to download a csv file. Currently, it downloads the file to my computer when I run the script. I would like to amend the download path to route it to a directory on my web host. Is there any easy way to do this with PHP?

Here is a quick summary of the PHP script that downloads the CSV file:

<?php 

$ch = curl_init(); 
//this is where I submit the form to download the csv file...
curl_close ($ch);  

header("Content-Disposition: attachment; filename=file_I_am_downloading.csv"); 
header("Content-Type: application开发者_如何学运维/octet-stream"); 
readfile("http://www.example.com/file_I_am_downloading.csv");
?>

To sum this up, I would like the script to be amended so that when I run this PHP file it downloads 'file_I_am_downloading.csv' to a specific directory on my host rather than first downloading to my computer. Thank you for your time and any direction you can provide is much appreciated.


$ch = curl_init();
.... curl setup
$data = curl_exec($ch);
if ($data === FALSE) {
   die(curl_error($ch));
}

// do this, instead of the header/readfile business.
file_put_contents('/some/path/on/your/webhost', $data);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜