PHP - Change File Permissions on Linux Server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ultra
Forum Newbie
Posts: 7
Joined: Tue Jul 08, 2008 12:00 am

PHP - Change File Permissions on Linux Server

Post by Ultra »

Hi,

I've been reading all over the i-net and could not find a solution to my problem here:

I'm accessing a php script in the backend admin part of my web application VIA WEB BROWSER which tries to delete a file.

I get permission denied errors.

I try to change permissions on the file but it won't let me.

Here's my code:

if(is_file($file_path))
{
// change file permissions
chmod($file_path, 0777);

// delete file
if(unlink($file_path))
{
echo "<p>file deleted !</p>";
}
else
{
echo "<p>file NOT deleted !</p>";
}
}
else
{
echo "<p>file does NOT exist !</p>";
}

Current file permissions are 644.

Any idea what I need to do ?

Thanx in advance for your help !

- M
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: PHP - Change File Permissions on Linux Server

Post by mikemike »

Could you give us the specific error you're getting?

Try changing the permissions to 0777 of the file you're deleting (I doubt this will make any difference).

Try changing the permissions of the file you're using to delete to 0777, this is more likely to work.

Failing that it might be a user/group issue, but we can't tell that without a specific error and more details.
Ultra
Forum Newbie
Posts: 7
Joined: Tue Jul 08, 2008 12:00 am

Re: PHP - Change File Permissions on Linux Server

Post by Ultra »

mike,

thanx for ypur reply.

I already tried to set the file permission of the file that is trying to delete the .zip file to 0777, does not do the job.

the error the server throws is:

regarding chmod(): "Operation not permitted in ... "

regarding unlink(): "Permission denied in ... "

Thanx.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP - Change File Permissions on Linux Server

Post by VladSun »

Who is the owner of the file and directory?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply