Page 1 of 1

permission denied after using chmod, why, how....

Posted: Thu Feb 21, 2008 10:01 am
by kryles
pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I am trying to write to a file on the server. When I try opening the file I get

Code: Select all

 
fopen(file.csv): failed to open stream: Permission denied in path/to/file.csv
 
Next I tried chmod() before opening the file to 0755

Code: Select all

 
if(file_exists("./file.csv"))
{
        chmod("./file.csv", 0755);
    $fp = fopen('./file.csv', 'w');
 
    $query = "SELECT name
              FROM names
              WHERE name = 'Jim'";
    $result = mysql_query($query);
 
        while($row = mysql_fetch_row($result))
    {
        fputcsv($fp, $row[0]);
    }
 
    fclose($fp);
}
 
and I get the following error.

Code: Select all

chmod(): Operation not permitted
My guess is this is a server issue? Some kind of setting on it is preventing me from using these? Or maybe I am using them wrong? Any suggestions would be helpful (The server is a hosting service, not my own).

Thanks,


pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: permission denied after using chmod, why, how....

Posted: Thu Feb 21, 2008 10:20 am
by Zoxive
The server probably doesn't have permissions in the folder which file.csv is in.

You need to change the permissions manually. (Not from within php, because that is the problem to begin with php can't modify that file)

Re: permission denied after using chmod, why, how....

Posted: Thu Feb 21, 2008 10:27 am
by kryles
Okay this is the hierarchy

Public_html -> folder1 (0715) -> file.csv(0644)

Wouldn't these allow access to the file? how should I change the permissions on them if not?

Thanks,

Re: permission denied after using chmod, why, how....

Posted: Thu Feb 21, 2008 10:32 am
by pickle
Ownership is probably the issue, not access permissions. If the user PHP is running as doesn't have rights to the file/directory, you won't be able to use PHP to change rights or ownership.

Like ~Zoxive said, you'll have to go in via the CLI & manually either set the ownership of the offending files/directories to be owned by PHP's user, or open up the privileges so the whole world can modify those files.

Re: permission denied after using chmod, why, how....

Posted: Thu Feb 21, 2008 1:22 pm
by Benjamin
Pickle is correct. You can also more than likely just ftp in to add global read permissions. The directory that the files are stored in will need to have execute permissions so that the apache user can open them.