Cant seem to write to file
Posted: Mon Mar 13, 2006 4:19 pm
Gents,
Me again ...
I have managed to open a file and write one line to it. Unfortunately I ami trying to write multiple lines to it. To shorten the explaination, I offer the following code extract followed by comments:
$handle = fopen($ufname,"w");
///File opens OK
Later on in the script...
if ($HdrCnt >= 1)
{
echo 'Writing header1 '.$header['Hrd1'];
fwrite($handle,$header['Hdr1']."\n");
}
/// This writes as expected
///Still later ...
while ($row = mysql_fetch_array($Data))
{
$buffer = implode(",",$row);
$DataLen = strlen($buffer);
echo 'Writing Buffer = '.$buffer;
$DatW = fwrite($handle,$buffer,$DataLen);
echo 'DataLen = '.$DataLen.', WriteLen = '.$DatW;
}
This produces a correct buffer (on the 1st echo) , no write into the file and on the second echo confirms correct len was passed and 0 bytes written.
I have run out of ideas as to why this is failing. Any hints are gratefully acknowleged.
BTW. This exports, from MYSQL a previously IMPORTED excel spreadsheet. If anyone is interested in this code, please send me an email (paul.beaudoin@hsbc.com) for some explanation and/or source.
Many thanks
Paul
Me again ...
I have managed to open a file and write one line to it. Unfortunately I ami trying to write multiple lines to it. To shorten the explaination, I offer the following code extract followed by comments:
$handle = fopen($ufname,"w");
///File opens OK
Later on in the script...
if ($HdrCnt >= 1)
{
echo 'Writing header1 '.$header['Hrd1'];
fwrite($handle,$header['Hdr1']."\n");
}
/// This writes as expected
///Still later ...
while ($row = mysql_fetch_array($Data))
{
$buffer = implode(",",$row);
$DataLen = strlen($buffer);
echo 'Writing Buffer = '.$buffer;
$DatW = fwrite($handle,$buffer,$DataLen);
echo 'DataLen = '.$DataLen.', WriteLen = '.$DatW;
}
This produces a correct buffer (on the 1st echo) , no write into the file and on the second echo confirms correct len was passed and 0 bytes written.
I have run out of ideas as to why this is failing. Any hints are gratefully acknowleged.
BTW. This exports, from MYSQL a previously IMPORTED excel spreadsheet. If anyone is interested in this code, please send me an email (paul.beaudoin@hsbc.com) for some explanation and/or source.
Many thanks
Paul