Page 1 of 1

format output using fwrite function

Posted: Tue Jul 29, 2003 6:01 am
by mesz
I am trying to format a newly created file by send ing a template to be written at the same time as a I send the data to be written to a file.
However the file still appears as a basic text window, and whats worse I lose the data that is entered - any idea why?

Code: Select all

<?PHP
$filename='/home/.sites/14/site467/web/test/test1/'.$thename .'.php';
$fp = fopen('list.dat',"a+");
  $line .= "|" . $HTTP_POST_VARS['thename'];
$line .= "\r\n";
fwrite($fp,$line);
fclose($fp);
$hoog = '/home/.sites/14/site467/web/template.php';
$Template = fopen($hoog, "r"); 
$fw = fopen($filename ,'w+');
  $line1 .= "|" .  $HTTP_POST_VARS['news'];
$line1 .= "\r\n";
fwrite($fw ,$line1, $Template);
fclose($fw);
?>
Only the first 3 characters of the $news variable are written to th newly created file.

Posted: Tue Jul 29, 2003 6:47 am
by mesz
This was so very not working that I tried another tack..

Code: Select all

<?PHP
require('/home/.sites/14/site467/web/template.php');
?>
<div class="main_col_L">
<font class="wwi">
<?PHP
$filename='/home/.sites/14/site467/web/test/test1/'.$thename .'.php';
$fp = fopen('list.dat',"a+");
  $line .= "|" . $HTTP_POST_VARS['thename'];
$line .= "\r\n";
fwrite($fp,$line);
fclose($fp);

$CallFunction=WriteToFile 
("<tr><td align="center">".$thename."</td></tr> 
<tr><td bgcolor="#0C2450"><img src="/home/.sites/14/site467/web/m.gif" height="15"></td></tr> 
<tr><td> 
<table bgcolor="#CCCCCC" border="0" align="center" cellpadding="0" cellspacing="0" width="500"> 
<tr align="center"><td align="left" width="500" class="content">" 
.$news." 
</td></tr>" 
); 
function WriteToFile($centerCopy)
{ 
$fw=fopen($filename, "a+"); 
fwrite ($fw, "$centerCopy\n"); 
fclose ($fw); 
} 
?>
I now have proper errors and everything:
Warning: fwrite(): supplied argument is not a valid stream resource in /home/.sites/14/site467/web/test/testwrite.php on line 26

Warning: fclose(): supplied argument is not a valid stream resource in /home/.sites/14/site467/web/test/testwrite.php on line 27

:!:

Posted: Tue Jul 29, 2003 7:30 am
by Tubbietoeter
globalize the $filename variable

function WriteToFile($centerCopy)
{
global $filename;
$fw=fopen($filename, "a+");
fwrite ($fw, "$centerCopy\n");
fclose ($fw);
}

Posted: Tue Jul 29, 2003 7:31 am
by Tubbietoeter
or give it to the function

function WriteToFile($centerCopy,$filename)
{

$fw=fopen($filename, "a+");
fwrite ($fw, "$centerCopy\n");
fclose ($fw);
}

Posted: Tue Jul 29, 2003 8:30 am
by mesz
Tubbietoeter,
Thank you very much - this works to perfection.
:lol: & :D & also :P