Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi there,


I am trying to allow users download a csv file from my website. This is the code I've been trying to use but it just opens a blank page and doesn't download anything. Any advice?


require_once (MYSQL);
require_once ('mysqli_connect.php');

$q="SELECT * FROM table_name";
$r = @mysqli_query($dbc, $q);
$html = "<table>";
$html .= "<tr><td>Song</td>";

$html .= "</tr>";
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))  {
$html .= "<tr><td>".$row['music_song']."</td>";
$html .= "</tr>";
$html .= "</table>";
header("Content-Type: text/csv");
header("Content-Disposition: attachment;filename=yourfile.csv");
echo $html;

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...