Php Unlink()?

admin

Administrator
Staff member
Hello,<br /><br />I have a system (almost) built so a client can go in and add/edit/delete content files from a directory from their website. However, I cannot get PHP to remove files and it's driving me crazy (so far all is good except the delete part). I have a strong feeling this is an issue with permissions where PHP sets the owner to nobody.<br /><br />So far I have PHP able to upload the file to a directory. The upload directory is set to 777 for testing.. After it uploads the file, I have PHP set the uploaded file to 0777 (using chmod('/home/user/path/file.txt')<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />, and it works correctly, as expected. Owner is set as nobody and the file's octal value is 0777. So you would think this would give PHP the ability to remove this file, right? Nope... When I try running an unlink('/home/user/path/file.txt'); command, it cannot delete the file, even with nobody owning the file and permissions set where everybody can rwx the file.<br /><br />So then I tried using ftp_connect(), ftp_delete(), etc... I was successfully able to have it connect, and change to the directory fine. When running the ftp_delete() function in PHP, it cannot delete any files either.<br /><br />Simply put, I cannot delete any files using PHP (no way that I know of). Has anybody experienced these problems? Does anybody have a workaround?<br /><br />Thanks much,<br />Erik<br /><br /><br />Edit by Erik: I figured it out. Sorry to bother! It was a problem in my code with urlencode/urldecode and my client giving weird filenames with non-standard characters. It does work! Rock Sign<!--content-->
Sounds like a cool script.<!--content-->
I use unlink() in my script and it works perfect. Only thing different is I use relative paths.<!--content-->
<!--QuoteBegin-erikn+Aug 1 2003, 09:40 AM--><div class='quotetop'>QUOTE(erikn @ Aug 1 2003, 09:40 AM)</div><div class='quotemain'><!--QuoteEBegin-->Owner is set as nobody and the file's octal value is 0777. So you would think this would give PHP the ability to remove this file, right?<!--QuoteEnd--></div><!--QuoteEEnd--><br /> No. Unix doesn't care what the permissions on a file are when you want to remove it.<br /><br />In fact, you can't remove a file. The only thing you can do in Unix is remove the *name*<br />of a file from a directory. Files may have several names. When all the names are gone,<br />the *system* removes the file and frees up the space.<br /><br />Since removing a name from a directory is a directory operation, not a file operation,<br />the only thing that matters is the permissions on the directory containing the name.<br />Unix doesn't care whether or not you have any permissions on the file. All that matters<br />is that the directory lets you remove the name. For that, you need Write and Execute<br />(search) permission on the directory. (e.g. 333 or 777 on the directory will do it.)<br /><br />If the userid of the person doing the removing matches the owner of the directory,<br />permissions 7xx are all that is needed. If the userid doesn't match, you the directory<br />must have "general" permissions, e.g. xx7.<br /><br />Directories with general permissions are accessible by Shell, CGI, or PHP scripts written<br />by anyone on your server - they are not private. Be careful.<!--content-->
 
Top