PHP unlink()中断file_exists、header和echo函数


PHP unlink() breaks file_exists, header, and echo functions?

我有以下代码:

$tmpfile = $tempDirectory . $file ;
if (file_exists($tmpfile)) {
   header('Location: <some location>');
}

它工作完美,文件存在,我被重定向到我的新页面。

所以,现在我知道该文件存在并且有效。所以,我进入FTP,确保文件在那里。

然后我运行这个代码:

$tmpfile = $tempDirectory . $file ;
if (file_exists($tmpfile)) {
   unlink($tmpfile);
   header('Location: <some location>');
}

重定向停止工作。PHP不输出任何内容。该文件将从FTP目录中删除。但是重定向完全失败了。

如果在If语句中存在取消链接时(在If语句的任何其他代码行之前或之后),在If语句内放入echo,则它不输出任何内容。

没有取消链接的错误,当我检查FTP时,文件显然被删除了,那么这里发生了什么?

当代码运行时,它会被删除,所以这显然不是权限问题。如果没有权限,它将无法删除文件。

感谢您的帮助。谢谢

解决方案可能很简单:

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

PHP也可能在unlink上崩溃。确保您的error_reporint设置设置为E_ALL。