我尝试在下载前更改文件名,但文件在下载后损坏。如何修复?
$origin_filename = 'orign_filename.exe';
$destination_filename = 'changed_filename.exe';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $destination_filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($origin_filename));
readfile($origin_filename);发布于 2021-03-02 00:06:43
我建议你使用这个函数(取自)
$origin_filename = 'orign_filename.exe';
$destination_filename = 'changed_filename.exe';
function force_download($file){
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-length: '.filesize($file));
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file);
exit;
}
force_download($destination_filename,$origin_filename);https://stackoverflow.com/questions/66424787
复制相似问题