Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用原始文件名下载PHP文件_Php_Curl_Download - Fatal编程技术网

使用原始文件名下载PHP文件

使用原始文件名下载PHP文件,php,curl,download,Php,Curl,Download,我正在寻找一种可能性,用PHP下载一个文件,并保留其原始名称 这应该适用于直接链接到文件(“foo.bar/test.zip”)和通过PHP文件代理的下载(“foo.bar/download.PHP?fileid=12345”可能类似于以下内容: $quoted = sprintf('"%s"', addcslashes(basename($file), '"\\')); $size = filesize($file); header('Content-Description: File

我正在寻找一种可能性,用PHP下载一个文件,并保留其原始名称


这应该适用于直接链接到文件(“foo.bar/test.zip”)和通过PHP文件代理的下载(“foo.bar/download.PHP?fileid=12345”可能类似于以下内容:

$quoted = sprintf('"%s"', addcslashes(basename($file), '"\\'));
$size   = filesize($file);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);

只需将$file替换为您要下载的文件。

谢谢,如果我使用指向文件的直接链接,这会起作用。但如果我使用指向php文件的链接,并将请求的文件代理给我,则不会起作用。您知道我如何实现这一点的可能性吗?您在代理脚本中使用了什么?
$quoted = sprintf('"%s"', addcslashes(basename($file), '"\\'));
$size   = filesize($file);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);