Problem with script - file permissions

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
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Problem with script - file permissions

Post by pentiumhead »

hi,

I have a script that needs to open and write to a file. It worked on my system but when i uploaded it to my hosting, the script will not run and i get the error:

Warning: fopen(output.php): failed to open stream: Permission denied in .......

how do i solve this problem

Kay
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

change the permissions so the script's user can write to the file. chmod()
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

This is what i got:

Warning: chmod(): Operation not permitted in /home/hyper/public_html/downloadp/chmod.php on line 9

Code:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
chmod("setup.php","0777");
?>

</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd guess your host disabled chmod(), as I guessed would happen.. you need to use your FTP client or your Host Manager to change the permissions then.
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

I opened windows ftp and typed remote and i got the message:

214-The following SITE commands are recognized
ALIAS
CHMOD
IDLE
214 Pure-FTPd - http://pureftpd.org/

how do i chmod?

Kay
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

quote chmod <permission> <filename>
replace <permission> and <filename> with their respective things.
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

I got this:

Warning: Unknown(/home/hyper/public_html/downloadp/setup.php): failed to open stream: Permission denied in Unknown on line 0

Warning: Unknown(/home/hyper/public_html/downloadp/setup.php): failed to open stream: Permission denied in Unknown on line 0

Warning: (null)(): Failed opening '/home/hyper/public_html/downloadp/setup.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in Unknown on line 0

What do i do now?

Thanks for your help

Kay
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what permissions did you set?
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

i set

quote chmod w setup.php
crazycaddy
Forum Commoner
Posts: 43
Joined: Fri Aug 05, 2005 6:59 am
Location: England, UK

Post by crazycaddy »

I don't know much about chmoding manually but shouldnt it be

chmod 777 setup.php
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

No luck

I connected to my server

and typed in the command line:

Code: Select all

ftp> quote chmod 777 setup.php
But still it didn't work.

kay
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try

Code: Select all

quote chmod 0646 setup.php
or other numbers (leaving the leading zero), such as 0746, 0766, but 0646 or 0746 shoudl do it.

Overall though, since you are writing to a php file, be very very very careful what you are writing in. If a user can control any aspect of the data being written, I'd be very very wary, because someone managing to inject a small amount of php code, can do wonderous amounts of damage.
User avatar
zippee
Forum Newbie
Posts: 9
Joined: Wed Jun 22, 2005 6:28 am
Location: England

Post by zippee »

Do you create the file/folder using php script? If yes then the owner of the file will be the server itself and you have no permission to change it. You can write another php script to change the file/folder permission and execute it on the server. Use chmod("setup.php","0777"); as provided in previous replies. Once you get there you can change the permission on your file manager or ftp (the file/folder is now open to all).
pentiumhead
Forum Newbie
Posts: 9
Joined: Wed Aug 17, 2005 11:24 am

Post by pentiumhead »

I've tried chmod(). It didn't work.

I've tried through my hosting control panel, i've tried by connecting through ftp.

If I don't get a solution to this. I think there is nothing more to do than contact the hosting personnel. Everything on my coding part should be correct i guess.

Kay
Post Reply