on-internet
← Community

PHP can't unlink file after fclose

Stack Overflow ·

After my script finishes I can delete the file, but while it's running I can't touch it, even after an fclose(). Here is the code I'm trying to use: $Files = glob("$_SERVER[DOCUMENT_ROOT]/files/*.csv"); $File = fopen($Files[0], "r"); //while (($Data = fgetcsv($File)) !== false) {... $i = 0; while (is_resource($File)) { $i && sleep(1); echo "Closing handle.\n"; fclose($File); if (++$i > 5) die("Could not close handle."); } foreach ($Files as $File) { $i = 0; while (file_exists($File)) { $i && sleep(1); echo "Deleting file.\n"; @unlink($File); echo 'www-data@debian:~$ ', $Command = "rm -f '$File

Comments

Sign in or sign up to comment and upvote.

No comments yet.