繁体   English   中英

如何设置PHP以将文件下载到特定目录?

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

我正在寻找关于这个的一般指导......

我创建了一个使用cURL下载csv文件的PHP脚本。 目前,它在我运行脚本时将文件下载到我的计算机。 我想修改下载路径,将其路由到我的Web主机上的目录。 有没有简单的方法用PHP做到这一点?

以下是下载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");
?>

总结一下,我希望修改脚本,这样当我运行这个PHP文件时,它会将'file_I_am_downloading.csv'下载到我主机上的特定目录,而不是先下载到我的电脑。 感谢您的时间,我们非常感谢您提供的任何方向。

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM