写了一个 文件下载的程序function download_file($filename){
//below to provide the download
if (file_exists($filename)) {
$file = fopen($filename);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename) . ' bytes');
//ob_clean();
//flush();
readfile($filename);
fclose($file);
return true;
}else{
echo("the file not exist");
return false;
}
//above to provide the download
}
但是没有进行 下载的功能。文件在上一步已经生成了。 但是如果我将 return true改成exit 下载功能可以实现,但是文件下载之后我还要进行其他的功能。请教大神们这是怎么回事? 我看网上的下载例子也不是说需要exit才可以的
//below to provide the download
if (file_exists($filename)) {
$file = fopen($filename);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename) . ' bytes');
//ob_clean();
//flush();
readfile($filename);
fclose($file);
return true;
}else{
echo("the file not exist");
return false;
}
//above to provide the download
}
但是没有进行 下载的功能。文件在上一步已经生成了。 但是如果我将 return true改成exit 下载功能可以实现,但是文件下载之后我还要进行其他的功能。请教大神们这是怎么回事? 我看网上的下载例子也不是说需要exit才可以的
#下面的操作
}else{
#错误提示
}
我去掉return 也已经试过了 不能够提供下载。
嗯 按照你 的想法 我试了一下 还是不行,我理解了一下我的这个错误似乎是这样的的,因为我的这段代码是放在一个action中,好像只有我跳出了这个action才能够进行下载。比如说我不用函数调用了 我直接将下载的代码粘贴进我的action中 return true还留下,这样的话在下载的时候跳出这个action 下载也是可以执行的。
在满足答件时,例如检查字段为非空,然后return true;页面才进行跳转,也才会调用你的action
这是表单提交常用的阻止异常提交的方法
下载功能算是一个表单吗?而且我的return true不是可以执行吗?