如果你需要下载特定的文件而不用另开新窗口,下面的代码片段可以帮助你。
function force_download($file) { $dir = ../log/exports/; if ((isset($file))&&(file_exists($dir.$file))) { header(content-type: application/force-download); header('content-disposition: inline; filename=' . $dir.$file . ''); header(content-transfer-encoding: binary); header(content-length: .filesize($dir.$file)); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename=' . $file . ''); readfile($dir$file); } else { echo no file selected; } }
复制代码
用法:
force_download(image.jpg);?>
复制代码
php