Page 1 of 1

Change Template

Posted: Mon May 30, 2005 5:20 am
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?

Posted: Mon May 30, 2005 6:10 am
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

?>

Posted: Mon May 30, 2005 11:25 am
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');