使用原始文件名下载PHP文件
我正在寻找一种可能性,用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
这应该适用于直接链接到文件(“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);