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!
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
<?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>";
?>
Last edited by azylka on Sat May 30, 2009 5:16 pm, edited 1 time in total.
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!