Page 1 of 1

File Editing Script

Posted: Sat May 30, 2009 4:46 pm
by azylka
I have this script and it says on line 10 (in red) that the function.open does not allow the script to open and edit my file. What's wrong?

EDIT: This is my error
Warning: fopen(uploads/index.html) [function.fopen]: failed to open stream: Permission denied in /home/a9133340/public_html/admin/edit.php on line 10

edit.php:

Code: Select all

<?php
// set file to read
$filename =$_GET['page'];
  
$newdata = $_POST['newd'];
 
if ($newdata != '') {
 
// open file 
[color=Red]$fw = fopen($filename, 'w') or die('Could not open file!');[/color]
// write to file
// added stripslashes to $newdata
$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write 
to file');
// close file
fclose($fw);
}
 
// open file
  $fh = fopen($filename, "r") or die("Could not open file!");
// read file contents
  $data = fread($fh, filesize($filename)) or die("Could not read file!");
// close file
  fclose($fh);
// print file contents
 echo "<h3>Contents of File</h3>
<form action='$_SERVER[php_self]' method= 'post' >
<textarea name='newd' cols='100%' rows='50'> $data </textarea>
<input type='submit' value='Edit'>
</form>";
?>

Re: File Editing Script

Posted: Sat May 30, 2009 4:49 pm
by Darhazer
Probably permission of the file is not set correctly :) Make sure your script have write permissions on the file
By the way, I can pass /etc/passwd (or another system file) to your script... Keep that in mind!

Re: File Editing Script

Posted: Sat May 30, 2009 7:04 pm
by azylka
Thanks for the suggestion. I got it to work a different way.