php下載文件代碼

function getFile($module, $id){
global $SESSION,$db,$tablepre;
$sql = "select attachment from {$tablepre}{$module} where id=$id and moderate=1";
$file = $db->fetchOneBySql($sql);
return $file;
}
$module = $_REQUEST['module'];
$id = $_REQUEST['id'];
$file = getFile($module, $id);
$dir1 = $site_engine_root . 'data/upload/';
$dir2 = $site_engine_root . 'data/upload/'.$module.'/';
$file = file_exists($dir1 . $file) ? ($dir1 . $file) : ($dir2 . $file);
if(is_file($file)) {
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
exit;
}else{
echo '<script type="text/javascript">window.opener=null;window.open(\'\',\'_self\');window.close();</sctipt>';
exit;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章