With code like this:, <a href="Myfile.csv">Open</a>you really are not doing any loading. However, if the client’s browser does not have the ability to read / display the file (in this case, the CSV file), it will force the user to download the file. In order to explicitly complete the download, you must set headerto tell the browser how to handle the request for the file in question. Consider this simplified Script:
PHP Script: CONTENTS HTML MARKUP
<?php
if(isset($_GET['d'])){
$file = htmlspecialchars(trim($_GET['d']));
processDownload($file);
}
function processDownload($fileName) {
if($fileName){
$dldFile = $fileName;
if(file_exists($fileName)){
$size = @filesize($fileName);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileName);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
return TRUE;
}
}
return FALSE;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Download Example</title>
</head>
<body>
<div class="container">
<div class="col-md-12">
<a href="index.php?d=Myfile.csv">Download CSV</a>
</div>
</div>
</body>
</html>
Hopefully this will give you a hint on how to do it your own way.
; -)