[英]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. 我创建了一个使用cURL下载csv文件的PHP脚本。 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.
我想修改下载路径,将其路由到我的Web主机上的目录。 Is there any easy way to do this with PHP?
有没有简单的方法用PHP做到这一点?
Here is a quick summary of the PHP script that downloads the CSV file: 以下是下载CSV文件的PHP脚本的快速摘要:
<?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. 总结一下,我希望修改脚本,这样当我运行这个PHP文件时,它会将'file_I_am_downloading.csv'下载到我主机上的特定目录,而不是先下载到我的电脑。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.