function download($data = false){
$file_name = '2013-07-01-093847test';
$extension = 'txt';
$filename = $file_name.".".$extension;
$upload_folder='path\to\folder\';
$uploadDir = WWW_ROOT.$upload_folder;
$file=$uploadDir.'\\'.$file_name;
$new_file=$uploadDir.'\\'.$filename;
copy($file, $new_file);
$ext = end(explode('.',$new_file));
if($ext && array_key_exists($ext,$file_types)){
if(file_exists($new_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/stream');
header('Content-Disposition: attachment; filename='.basename($new_file));
header('Content-Transfer-Encoding: binary');
header('Expires: 78000');
header('Cache-Control: private');
header('Pragma: public');
header('Content-Length: ' . filesize($new_file));
#readfile($new_file);
unlink($new_file);
exit;
}
}
else {
die('The provided file path is not valid.');
}
}
当我尝试使用extjs界面中的上述代码下载文件时,文件内容会显示在firebug控制台部分而不会下载到客户端计算机上?