I'm trying to create a function that allows users to download files. When I click a button to download the file this function is called and I'm getting the "Cannot modify header information - headers already sent by" error.
From what I know, the "headers already sent..." error is caused by whitespace, but I can't seem to find anything. Is there something I'm not taking account of? This is NOT the only function on the page where it's located. Do I have to load the page a special way?
function serveFile($fileID){
$sql = mysql_query("select filename from files where id = '$fileID'");
$file = mysql_fetch_array($sql);
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$file['filename'].'" ');
readfile('/user_files/'.$fileID.' ');
}
Update - I got it to work, thanks for the tips. I moved the function call to the top of my page.