I can't download excel file, it downloads the file but it doesn't have a contents and its size is 0kb. This is my html code.
<h5 style="color: red;">
<a href="2.php?file=files/Battle_Entry_form.xls" class="links">
Click here to download A Registration form
</a>
</h5> <br />
2.php (this is my php codes for downloading excel file)
<?php
if(isset($_GET['file'])){
$filename = $_GET['file'];
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile("http://www.caledtech.com/batllewebsite/".$filename);
exit;
}
?>
Is there something missing in my codes?
The PHP manual of readfile said:
I think you should use file_get_contents instead of readfile:
And I recommend to you to use basename for the filename: