Hi Everyone,
I'm having some issues with fwrite(). I've written an uploading script to upload an exported CSV file. Unfortunatly, the file is, for reasons beyond my control, exported as a binary file, complete with M's and no newlines.
I've written a short function to open the file, strip the M's and write the data back.
Heres the code:
@ $fp = fopen("$uploadedfile","r");
while(!feof($fp))
{
$line = fgets($fp,25853);
$fileArray = split("^M",$line);
foreach($fileArray as $entry)
{
$liveFile = fopen("$datafile","w");
if($liveFile)
{
fwrite($liveFile, "$entry\n");
}
else
{
print "Could not create file handle";
}
fclose($liveFile);
}
}
I know that the value $entry is format ok because, if i print the values to the browser, it comes out fine. It just doesn't seem to write to the file correctly.
Can anyone see anything wrong here?
Cheers,
steve