Jump to content

excel CSV file for download


Recommended Posts

csv file is fairly easy to create with PHP. And of course Excel can open any csv file quite easily. The data won't look pretty, but that's not what it's supposed to do. Um, if theres a tutorial on EXACTLY what you want to do? I'm not sure.

 

But you will want to become familiar with PHP's fopen, and all that for file handling. And explode() and implode() you will probably use. The information your saving to the csv files is from MySQL or some other source, and I'm assuming you can read from there.

if suppose i have a mysql database

 

and i want to get data from mysql & then make CSV file for download so now how can i do that ?

 

can u help me out ?

 

 

No need to waste space on your server's HD by saving a file:

 

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename='foo.csv'");
$data="col1, col2, col3, \n";
echo $data;
?>

 

Best,

 

Patrick

myharshdesigner, please provide the code you have already tried. if you wish for someone to write the complete code for you, then try posting for paid help in the Freelance board. A Google search for PHP and CSV will provide you with the resources - there's no point getting code if you're not going to be able to understand it, as you'll end up with tonnes more problem down the line.

<?php
$data = "";
$row = 'first value,';
$row .= 'second value,';
$row .= 'third value';
$data .= $row."\n";

$row = 'fourth value,';
$row .= 'fifth value,';
$row .= 'sixth value';
$data .= $row."\n";

// Output the headers to download the file
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=log.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $data;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.