File Editing Script

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
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

File Editing Script

Post 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>";
?>
Last edited by azylka on Sat May 30, 2009 5:16 pm, edited 1 time in total.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: File Editing Script

Post 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!
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

Re: File Editing Script

Post by azylka »

Thanks for the suggestion. I got it to work a different way.
Post Reply