[英]Is there any way to move a file from server to local directory using?
我在php / javascript / xul中搜索网络以获取功能/命令,该功能/命令可以将文件从http服务器传输到本地目录,但是找不到足够的答案。
使用PHP / Javascript / XUL中的任何一种,是否有任何功能/命令可以完成此工作?
这无法使用javascript完成,但是在PHP中,您必须发送适当的标头,然后按以下方式提供文件:
示例:强制下载CSV文件
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=example.csv');
header('Pragma: no-cache');
readfile("/path/to/yourfile.csv");
这是用于文件下载的php脚本:
if (file_exists($file))
{
if (FALSE!== ($handler = fopen($file, 'r')))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: chunked');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//Send the content in chunks
while(false !== ($chunk = fread($handler,4096)))
{
echo $chunk;
}
}
exit;
}
echo "<h1>Content error</h1><p>The file does not exist!</p>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.