Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to download any CSV file while working with PHP

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 237
    Comment on it

    /* Header file to includes.

    fopen is use to open a file in write mode here.

    fputcsv function is use to output the CSV file having the name of columns and data coming from database. */

    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename=attendance.csv');
    $output = fopen('php://output', 'w');
    fputcsv($output, array('Column name 1','column name 2'));
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result))
    fputcsv($output, $row);

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: