douhan8009 2012-08-21 23:01
浏览 85
已采纳

PHP unlink()打破了file_exists,header和echo函数?

I have the following code:

$tmpfile = $tempDirectory . $file ;

if (file_exists($tmpfile)) {

   header('Location: <some location>');

}

It works flawlessly, the file exists, I get redirected to my new page.

So, now I know that the file exists and works. So, I go into FTP, ensure the file is there.

Then I run this code:

$tmpfile = $tempDirectory . $file ;

if (file_exists($tmpfile)) {

   unlink($tmpfile);
   header('Location: <some location>');

}

Redirect stops working. PHP outputs nothing. The file gets deleted from the FTP directory. But the redirect completely fails.

If I put an echo inside the if statement when there is an unlink present (before or after any other line of code in the if statement, it outputs nothing.

There isn't an unlink error, and the file is clearly deleted when I check FTP, so what is going on here?

It gets deleted when the code is run, so it's obviously not a permission issue. It wouldn't be able to delete the file if it didn't have permissions to do so.

Any help is appreciated. Thanks!

  • 写回答

1条回答 默认 最新

  • dongsu7049 2012-08-21 23:15
    关注

    Solution may be simple:

    [blank space] - this breaks redirect
    <?php
    
    // code
    

    PHP may be also crashing on unlink. Make sure your error_reporint setting is set to E_ALL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样