写了一个 文件下载的程序
- PHP code
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才可以的
------解决方案--------------------
看你在哪调用这个函数,检查下在哪里调用的,那里是不是有问题?
------解决方案--------------------
这样呢:
- PHP code
if(download_file($filename)){
#下面的操作
}else{
#错误提示
}
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
你那个函数return false就相当于preventDefault不会提交表单
在满足答件时,例如检查字段为非空,然后return true;页面才进行跳转,也才会调用你的action
这是表单提交常用的阻止异常提交的方法