-2

I can't delete a file using unlink() and when I use fopen with the "w" tag, I get an error. The file has 777 chmod. I can use fopen() to write at the end of the file. But I can't delete anything. Can anybody help me please?

Here's a sample:

   echo substr(sprintf('%o', fileperms('..')), -4); //777
   echo substr(sprintf('%o', fileperms('.')), -4); //777
   echo substr(sprintf('%o', fileperms('test')), -4); //777
   chmod('tmp',0777);  //Permission denied
user1319182
  • 481
  • 12
  • 26

2 Answers2

2

To unlink a file, you need write permission on the directory it's in. Having the file itself chmod'd 777 won't help

je4d
  • 7,628
  • 32
  • 46
0

I've run into this issue before and been able to remedy by forcing garbage collection after closing the file and before unlinking it:

gc_collect_cycles();

By far not the best solution, but it did resolve an issue I had deleting files that had been previously opened and closed lines before.

Bryant Makes Programs
  • 1,493
  • 2
  • 17
  • 39