• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 文件下载失误

php 搞代码 3年前 (2022-01-23) 64次浏览 已收录 0个评论

php 文件下载出错
写了一个 文件下载的程序

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function download_file($filename){     /<i style="color:transparent">本文来源gaodai$ma#com搞$$代**码)网8</i><strong>搞代gaodaima码</strong>/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{  #错误提示}
------解决方案--------------------

探讨

写了一个 文件下载的程序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
这是表单提交常用的阻止异常提交的方法


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 文件下载失误

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址