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);

Recommended Answers

All 2 Replies

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.

Member Avatar for diafol
[B]$surce[/B]= str_replace($oldname,$newname,$source);

wrong name.

Renaming a file is simple:

rename("/files/oldname.txt", "/files/newname.txt");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.