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
Cant seem to write to file
- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
Gents,
I know it is bad form to answer yourself ( and indeed somewhat suspect to be talking to one's self...) But as I have a partial answer ...
There seems to be a bug (or undocumented behavoiur) with fwrite in as much as when a trailing '\n' is not present in the buffer, it fails to write. After some testing, it appears that somewhere on the PHP/VMS border if there is no linefeed char (denoting end of line here), the line refuses to write and it (correctly) reports 0 chars written with no further errors (or hints). To me this is unexpected - does any one else agree?
Thanks and regards
Paul
I know it is bad form to answer yourself ( and indeed somewhat suspect to be talking to one's self...) But as I have a partial answer ...
There seems to be a bug (or undocumented behavoiur) with fwrite in as much as when a trailing '\n' is not present in the buffer, it fails to write. After some testing, it appears that somewhere on the PHP/VMS border if there is no linefeed char (denoting end of line here), the line refuses to write and it (correctly) reports 0 chars written with no further errors (or hints). To me this is unexpected - does any one else agree?
Thanks and regards
Paul