problem with downloading csv file

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

Post Reply
B.Murali Krishna
Forum Commoner
Posts: 28
Joined: Fri May 12, 2006 2:05 am
Location: Hyderabad,India
Contact:

problem with downloading csv file

Post 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]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
Post Reply