php 文件下载出错
写了一个 文件下载的程序
php codefunction 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 codeif(download_file($filename)){ #下面的操作}else{ #错误提示}
------解决方案--------------------
探讨
写了一个 文件下载的程序php code
function download_file($filename){
//below to provide the download
if (file_exists($filename)) {
$file ……
------解决方案--------------------
探讨
引用:
这样呢:
php code
if(download_file($filename)){
#下面的操作
}else{
#错误提示
}
不太明白你说的 你说的也是将return给省略了吗? return省略去了 我也不可以运行
------解决方案--------------------
你那个函数return false就相当于preventdefault不会提交表单
在满足答件时,例如检查字段为非空,然后return true;页面才进行跳转,也才会调用你的action
这是表单提交常用的阻止异常提交的方法