Page 1 of 1

problem with downloading csv file

Posted: Sun Jan 07, 2007 1:07 am
by B.Murali Krishna
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello, 
I have a problem with downloading csv file, before down loading i am writing it and saving it into one folder after that i am downloading it by it's name. But i am getting the data after one row of csv file, ie, the first line is kept empty.

My Script will be:

Code: Select all

$fp1 = fopen(DIR_FS_DOCUMENT_ROOT.'import/' . $file_name,"rb");
            $buffer = fread($fp1, filesize(DIR_FS_DOCUMENT_ROOT.'import/' . $file_name));
            fclose($fp1);
            header('Content-type: application/csv');
            header("Content-disposition: attachment; filename=\"$file_name\"");
            echo $buffer;
           ob_end_flush();
            exit;
Thank U
Murali


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Jan 09, 2007 8:51 pm
by aaronhall
Are you sure that the first line is being written to the file in the first place? If it's just white space that you're looking to remove, you could trim($buffer) before dumping it to the browser. Also, if you aren't opening binary files, you could use file_get_contents() instead to clean up the code a little.