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
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Jul 29, 2003 6:01 am
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.
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Jul 29, 2003 6:47 am
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
Tubbietoeter
Forum Contributor
Posts: 149 Joined: Fri Mar 14, 2003 2:41 am
Location: Germany
Post
by Tubbietoeter » Tue Jul 29, 2003 7:30 am
globalize the $filename variable
function WriteToFile($centerCopy)
{
global $filename;
$fw=fopen($filename, "a+");
fwrite ($fw, "$centerCopy\n");
fclose ($fw);
}
Tubbietoeter
Forum Contributor
Posts: 149 Joined: Fri Mar 14, 2003 2:41 am
Location: Germany
Post
by Tubbietoeter » Tue Jul 29, 2003 7:31 am
or give it to the function
function WriteToFile($centerCopy,$filename)
{
$fw=fopen($filename, "a+");
fwrite ($fw, "$centerCopy\n");
fclose ($fw);
}
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Tue Jul 29, 2003 8:30 am
Tubbietoeter,
Thank you very much - this works to perfection.
& & also