Jump to content

Access Denied To Php's Unlink Command


Dman8568
 Share

Recommended Posts

I am currently writing a file management service, in PHP, for my website where Admins can upload viewable files (html, pdf, txt, ect.) for members to view. All is working fine until I started to code the "Delete File" portion.

 

When I tell it to delete a file I get a "Permission denied" error back. I have tried both local file system address (/home/[cpanelname]/...) and I get the “Permission denied” error. And when I try the URL (http://www...) I get a "File does not exist" error, when in fact it does.

 

Is the unlink command blocked on the servers and if so, is there a work-a-round?

 

 

 

Many Thanks,

David

Link to comment
Share on other sites

I suspect the "Permission denied" message is not related to using the 'unlink' command, but rather, your script does not have appropriate directory permissions to delete the file.

 

To delete a file, the script, running as the user 'nobody', must have write permissions for the directory that contains the file.

 

If you own the directory (you created it), that directory would need to have 0777 permissions. If 'nobody' owns the directory (a PHP script created it), the directory should have at least 0755 permissions.

Link to comment
Share on other sites

...

If you own the directory (you created it), that directory would need to have 0777 permissions. If 'nobody' owns the directory (a PHP script created it), the directory should have at least 0755 permissions.

 

 

the target directory is inside my media folder. The media folder is then sub-divided by file extentions (htm folder, img folder, etc.) All the sub-division folders were created by me through SmartFTP.

 

Therefor, I would need to set the folder to 0777? But isn't that a security risk? (setting a public folder to 0777)

Link to comment
Share on other sites

Therefore, I would need to set the folder to 0777? But isn't that a security risk? (setting a public folder to 0777)

Yes, but it is the only way you'll be able to accomplish what you're wanting to do. To minimize the risk, you'd want to make sure your scripts are secure, that no one can upload just any file into that directory, and make regular backups of your site, as this directory would be vulnerable if any account on your server is compromised.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...