0

Please help me to open at html file from the server ,edit and save it, using php.
The code below returns a blank page i.e. no syntax errors but no output. home.htm is the exact name of the file on the server and it has 776 permisions.

$openedfile =fopen(home.htm,'r+'); //open a file on the server for reading and writing

$openedfile=file_get_contents($openedfile);

echo $openedfile;
$filesize = filesize(home.htm); //the size in bytes of the file

$filecontent= fread($openedfile, $filesize);

echo $filecontent;

//$filecontent= str_replace('var newname = '$oldname', 'var newname = '$newname'', $filecontent); //replaces name

fclose($filecontent);

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

I have now managed to open and edit the file but the result is not saved on the server:

$source= implode(' ', file("home.htm"));
$surce= str_replace($oldname,$newname,$source); //updates name in source string

echo $source; // displays the correctly edited version of the html page

fclose($source); // but home.htm remains unchanged on the server.

0
[B]$surce[/B]= str_replace($oldname,$newname,$source);

wrong name.

Renaming a file is simple:

rename("/files/oldname.txt", "/files/newname.txt");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.