0

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

<?php

// 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'>"
    ."</form>";

}
if(isset($act)){
    
   return create();
}
// This function will create your file
function create(){

// Gather info into variables from our form
$sade="index.php";


$filename = $_REQUEST['filename'];
$filename=$filename.'.php';

$content1=fopen($sade,'r')
$content = fread[$content1,"a"];
$act=$_REQUEST['act'];
// 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


}


form();





?>

Edited by azegurb: n/a

3
Contributors
8
Replies
11
Views
7 Years
Discussion Span
Last Post by azegurb
0

So what's the problem with the code?

0

hi
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

0

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

0

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

0

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.

0

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.

Example
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.

/about_us.php

which could have this format:

<?php
$title = "About us ...";
$keywords = "about us, company details, contact info ...";
$description = "This is about us - the company ...";
include("includes/top.php");
$page = basename($_SERVER['PHP_SELF']);
include("content/$page");
include("includes/bottom.php");
?>

The first three variables can be added via textboxes.

/content/about_us.php

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

Your top.php could look something like this:

...any common php functions / DB connection code etc...
...DTD...
<html ...>
<head>
<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.

0

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

0

oh sorry just i saw it
i will try it

Edited by azegurb: n/a

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.