This is my first time trying to send a file to the user using php and I have the following setup:
if (file_exists($fullPath)) {
    header('Content-type: text/csv');
    //Use Content-Disposition: attachment to specify the filename
    header('Content-Disposition: attachment; filename='.basename($fullPath));
    //No cache
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    //Define file size
    header('Content-Length: ' . filesize($fullPath));
    ob_clean();
    flush();
    readfile($fullPath);
}else{
    echo "alert(\"File name is NOT FOUND: ".$fullPath."\");";
}
This does grab the file but it displays the file on the webpage as if I echo-ed the file contents. The script that holds this code is included with a require statement. If I manually call this single file by navigating to it through the browser, the file gets downloaded but If this script is included as a required statement within another script, then the file is not downloaded but just outputted to the screen.
My suspicion is that there may be some issue with the headers but I am not sure if that's the issue.
