简体   繁体   中英

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM