To create a CMS in PHP, is the best way to do it to save sections of the html to either say either a db or text file. This seems a bit messy but maybe the best way, for example say i have this html and i want to have a user be able to add more images to their page by just uploading an image and clicking a button ........,

HTML Code:

HTML Code:
<table>
   <tr>
    
     <td> <img src = "i1.jpg" ></td>

   </tr>
</table>

Now i could save,

HTML Code:

HTML Code:
<table>
   <tr>
to say text1.txt

and

HTML Code:

HTML Code:
</tr>
</table>
to text2.txt,

and the images to say text3.txt,

HTML Code:

HTML Code:
 <td> <img src = "i1.jpg" ></td>

i could then say something like,


PHP Code:
<?php

$fname 
"text1.txt";

$fo fopen($fname,r);

$fr1 fread($fo,filesize($fname));

fclose($fo);


$fname "text2.txt";

$fo fopen($fname,r);

$fr2 fread($fo,filesize($fname));

fclose($fo);


$fname "text3.txt";

$fo fopen($fname,r);

$fr3 fread($fo,filesize($fname));

fclose($fo);

$f_final=   $fr1.$fr3.$fr2;

echo 
$f_final;

?>
This would put the contents of all 3 text files into a single variable $f_final so that all i would need to do if i needed a new image added is add that images html to text3.txt.

This seems like a pretty good way of doing things, i assume this is how CMS systems are made pretty much??

So basically i could have a user frontend "addimg.html" which is for adding the image,




HTML Code:
<form method="post" action ="newimage.php">

<input tpye = "text" name = "img1">
<input type = "submit">

</form>
and then a modified version of the above php,


PHP Code:
<?php

//save new image name to text3.txt ***********
$newimgge_to_ADD $_POST["img1"];

$fname "text3.txt";

$fo fopen($fname,a);

fwrite($fo,"\r\n".'<td> <img src = "'.$newimgge_to_ADD.'.jpg"> </td>');

fclose($fo);
//**********************

//Open all the text files one by one and save their contents to a variable *****
$fname "text1.txt";

$fo fopen($fname,r);

$fr1 fread($fo,filesize($fname));

fclose($fo);


$fname "text2.txt";

$fo fopen($fname,r);

$fr2 fread($fo,filesize($fname));

fclose($fo);


$fname "text3.txt";

$fo fopen($fname,r);

$fr3 fread($fo,filesize($fname));

fclose($fo);

//******************

//Combine the contents of all 3 varables to one varable f_final  **********

$f_final=   $fr1.$fr3.$fr2;

//*********************

//Print out the result *********************

echo $f_final;

//**************************


?>
This would need a good bit of tweaking but i just want to know if i am on the right tracks..