hi all
i have a problem with file content copying. i have index.php and there are codes in it. i would like to create indexa.php and append index.php file contents to newly created indexa.php file
thanks beforehands
here is my file


// This function shows your form
function form(){

echo "<form action='?act=create' method='post'>"
    ."Faylin adi olacaq: <input type='text' name='filename' size='30'><br>"
    ."<textarea cols='50' rows='10' name='content'></textarea><br>"
    ."<input type='submit' value='Create'>"

   return create();
// This function will create your file
function create(){

// Gather info into variables from our form

$filename = $_REQUEST['filename'];

$content = fread[$content1,"a"];
// Now let's create our file
$open = fopen($filename, "a"); // Now this file is ready for overwriting
fwrite($open, $content); // This will write your text what was in textarea into your file
fclose($open); // Closes your file



Member Avatar

So what's the problem with the code?

i create file with extension php. and i have also one index.php file
i would like to append its (index.php) code to newly created file.
is it possible
thank you for attention

Member Avatar

Sounds to me as if you're trying to create a template?
file_get_contents() and file_put_contents() are nice functions.

yes as you said i would like to create template
i tried this fucntions but nothink i got,
can you explain it on my code pls
thanks for attention

well, I know a set of functions that work for sure, not sure they are the best method, but they work on copying any file content from server to another even.

google Curl functions, you will find done examples.

Member Avatar

If you are trying to produce templates, could I suggest you try a different method? Actually hard-coding 'common markup/code' into every file is not templating. This is just replication/duplication. Don't do it! If you need to change the main template, you need to change all the files.

You need to put your common bits into files.

For common dtd/head area/top body tag/navigation/side bars etc (stuff that appears before the main content) - put them into a file called 'top.php' and save under a folder called 'includes' (could be anything, though). Do the same for anything that comes below the main content - put it into 'bottom.php', also under the 'includes' folder.

Create another folder called 'content'.

When you create a new file, two files are created - one main file in the root directory and an identically names one under the contents folder, e.g.


which could have this format:

$title = "About us ...";
$keywords = "about us, company details, contact info ...";
$description = "This is about us - the company ...";
$page = basename($_SERVER['PHP_SELF']);

The first three variables can be added via textboxes.


<div id="content">
  <p>This is about us</p>

Your top.php could look something like this:

...any common php functions / DB connection code etc...
<html ...>
<title><?php echo $title;?></title>
<meta name="keywords" content="<?php echo $keywords;?>" />
<meta name="description" content="<?php echo $description;?>" />

Sorry, getting carried away. Suffice to say, use include files to make a simple templating system - don't use duplication - it can't be maintained very easily.

thanks but where is the top.php file
or its my while which i have posted

oh sorry just i saw it
i will try it