du7133 2013-11-10 12:08
浏览 97

为什么有些代码不会在标题(“Content-disposition:...”)行之后运行?

I was wondering if anyone know why the code after the header(Content-disposition: ...) will not run? It writes and downloads the file, but it will not run the unlink() line...

This code is within a few other if statements originally.

Here is the code:

$form1Array = array($_POST["namn"], $_POST["stad"]);
$form1String = serialize($form1Array);
$form1Fil = $_POST["namn"].".txt";
$midMappe = "midlertidig\\";
$fo_form1Fil = fopen($midMappe.$form1Fil, "w");
//
if (fwrite($fo_form1Fil, $form1String)) {
    ignore_user_abort(true);
    //
    header("Content-type: text/plain");
    header("Content-disposition: attachment; filename=".$form1Fil);
    //
    unlink($midMappe.$form1Fil);
    } else {
       echo "Could not save the file for download.";    
    }

Thank you. :)

  • 写回答

2条回答 默认 最新

  • duancui19840401 2013-11-10 12:21
    关注

    The code will be correctly executed and as someone pointed out in the comments, it is very likely that the problem is in the unlink() function. I recommend you to do a quick debug and see what unlink() returns. More in particular, see if it return false (it will if it fails to unlink the file).

    Here an example of what i mean

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题