PDA

View Full Version : PHP Unlink problem



tpspoons
July 7th, 2008, 06:04 PM
Alright I am a total PHP noob, so bare with me :P

OK I'm using PHP to delete a file specified in a flash app (Sorry but I can't show you it :(), the code is extremely simple (I've cut out the code thats unrelated):


<?php
echo (unlink ($_POST ['file']));
?>

OK the problem is, once the file is deleted a new file is appears, with a name such as '.nfs37260B3' which is deleted within a few seconds. Unfortunately the app refreshes the contents of the folder as soon as the delete if complete, so the new file appears on the list. Is this a temporary file made in order to delete the file :h:

Anyway the problem only seems to occur once tested on the server, on my machine it seems to work fine. Well either that or the new file disappears before the contents of the folder are refreshed :/

Any help appreciated.

Esherido
July 7th, 2008, 10:10 PM
What operating system are you using? I think you are right about this temporary file being using by the operating system's file-system in the process of deleting the file.

A simple solution that comes to mind is to only search the directory for normal files. (EG: Those that have characters before and after a dot.) A simple regular expression to do this would be: ".+\..+"

Jeff Wheeler
July 8th, 2008, 12:37 AM
Looks like it’s using NFS. It will create temporary files sporadically to do random stuff, and there’s not really anything you can do to avoid it except not use NFS to mount your files. Googling for “nfs files” finds a lot of information regarding them, but essentially everything comes to the same conclusion. Just ignore them.

To hide hidden files (Esh is correct in that hidden files are prefixed with a dot), you could also use this regular expression: ^[^.], which unlike Esh’s, actually works. :P

tpspoons
July 8th, 2008, 06:40 AM
Thanks alot I'll try it now :D

Esherido
July 8th, 2008, 07:56 AM
To hide hidden files (Esh is correct in that hidden files are prefixed with a dot), you could also use this regular expression: ^[^.], which unlike Esh’s, actually works. :P
:lol: Ouch, that kind of hurt. But yeah, I didn't even bother testing that Regex because I suspected that someone with much more Regex knowledge (I read Mastering Regular Expressions about a year ago (It's the 1996/1997 edition.) but still don't feel like a Regex Master.) would come in here with a much better solution.

I just took a sec to actually test my regular expression and it does work. :to:

Jeff Wheeler
July 8th, 2008, 09:34 AM
I just took a sec to actually test my regular expression and it does work. :to:

No it doesn’t. It should do the opposite on these cases:

.filename.extension (should be hidden)
valid_filename (shouldn’t be hidden)

Plus, it’s stupidly complicated.

:P

Esherido
July 8th, 2008, 01:01 PM
The too reasons you stated are inconsequential because I choose to ignore them. Besides, my solution is more simple than your solution. :P

Jeff Wheeler
July 8th, 2008, 08:21 PM
Err … whatever.

Esherido
July 8th, 2008, 08:25 PM
:lol: For once I win an argument against the mighty Jeff.

hl
July 9th, 2008, 11:21 AM
I disagree; you lost. He just didn't want to reply to you. That's how bad your response was. :)

Esherido
July 9th, 2008, 12:46 PM
:lol: Actually, it was that great, he was just dumbfounded by my knowledge.