Current location: Hot Scripts Forums » Programming Languages » PHP » Permissions denied with PHP fopen, chmod etc


Permissions denied with PHP fopen, chmod etc

Reply
  #1 (permalink)  
Old 07-11-03, 04:54 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Permissions denied with PHP fopen, chmod etc

Hi, I'm very new to PHP.

I got lucky on the first 2 servers I made this editor app for and now I can't get it to work properly on 2 others. I am trying to fopen any local files on the servers I maintain with my own "editor" but I get the following errors. I would rather not have to manually chmod every directory and file by hand just to make it work! BTW, I chmod the entire root directory to 777 but newly uploaded files are defaulting to 644 and seem to need to be at least 646 to be "fopen"able.

"Warning: fopen(../../experience/index.html) [function.fopen]: failed to create stream: Permission denied in /home/shinymac/public_html/_zbox/phpeditor/save.php on line 43"

This warning comes from my "save file" page after the edits have been made and approved. Here is the code without any attempts at chown? or chmod since I do not know how to do it properly or even what an really owner is.

Code:
<?
$filename = $_POST['filename'];
$relative_filename = $_POST['relative_filename'];
$tempBak = $_POST['tempBak'];
$tempEdit = $_POST['tempEdit'];

// get contents of temporary storage file I successfully created with fopen on previous pages
$newPage = file_get_contents($tempEdit);

// $relative_filename is var containing a path to file in form of ../../news/index.php

$handle = fopen($relative_filename, 'wb'); 
fwrite($handle, $newPage);
fclose($handle);

unlink($tempEdit);
unlink($tempBak);
Thanks for your helping me with this. If you need any more info let me know!

- Paul
Reply With Quote
  #2 (permalink)  
Old 07-11-03, 10:55 AM
Man Down Man Down is offline
HS Staff
 
Join Date: Jun 2003
Location: Maryland
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Add this line above $handle = fopen(...

chmod ("/path/to/file/filename", 0666);

Of course you have to change the path and file name in that line of code.

If you need more assistance let me know.
__________________
Man Down
Reply With Quote
  #3 (permalink)  
Old 07-13-03, 04:01 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Actually I am having this problem earlier in my script than the code I pasted up before but it is similar in nature. When I try to create a backup file in the form of index.bak.html. The only way I know to create a file is to try to fopen it and if it doesn't exist PHP creates it for me. Here is the code I am using:

PHP Code:



// == make a temp file variable name from the name of page I wanna edit ===
$tempBak substr_replace($relative_filename'.bak'$ext0);

// ==== make said tempfile now ====
$handle fopen($tempBak'wb'); 
fwrite($handle$page);
fclose($handle); 
I am told this error:
Warning: fopen(../../index.bak.html) [function.fopen]: failed to create stream: Permission denied in /home/domain/public_html/test/phpeditor/edit.php on line 62

Apparently I cannot chmod yet or chown or touch since the file doesn't exist at this point.

Thanks for replying - Paul
Reply With Quote
  #4 (permalink)  
Old 07-13-03, 07:18 AM
Steven Steven is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Singapore
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
maybe try to chmod the folder and file in phpeditor directory?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM


All times are GMT -5. The time now is 10:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.