Change Template

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Change Template

Post by S_henry »

Let say I have a template of letter in my system (eg Formal letter - letterA.php). Is it possible if i want to change the template using my system. For example, i view the template (eg. Letter A) inside textarea. And then i change the template inside that textarea and click Save button. And then the template will be saved into the system. Anybody got any idea how to do it pls?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yes it can be done. For example...

Code: Select all

Directories (for example):

   '/home/user/public_html/'
      'change_template.php'
      'view_template.php'  
 
   '/home/user/public_html/templates/'
      'template_1.htm'

Code: Select all

<form action=&quote;change_template.php&quote;>
<textarea name=&quote;document&quote;>
<?= file_get_contents($template_path); ?>
</textarea>
<input type=&quote;hidden&quote; name=&quote;template_path&quote; value=&quote;<?= $template_path; ?>&quote; />
<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;Save&quote;>
...

Code: Select all

<?php

$tpl = stripslashes($_POSTї'template_path']);
$doc = stripslashes($_POSTї'document']);

$handle = fopen($tpl, 'w+');
fwrite($handle, $doc);
fclose($handle);

//do whatever

?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

if you're on a windows server, you might also want to include a "b" for your mode parameter to force binary mode...just an idea to save you a headache if it doesn't work doing as d11 suggested:

Code: Select all

$handle = fopen($tpl, 'wb');
Post Reply