Download any File without read Exact file location.
1 2 3 4 5 6 7 8 9 | <?php //download.php //content type header('Content-type: text/plain'); //open/save dialog box header('Content-Disposition: attachment; filename="resume.docx"'); //read from server and write to buffer readfile('resume.docx'); ?> |
Dynamic Download Files in PHP
Index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td align="center" valign="middle"><a href="file.php?file=resume.docx"><img src="button.jpg" width="150" height="50" border="0" /></a></td> </tr> </table> <table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td align="center" valign="middle"><a href="file.php?file=photo.jpg"><img src="button.jpg" width="150" height="50" border="0" /></a></td> </tr> </table> <table width="100%" border="0" cellspacing="10" cellpadding="0"> <tr> <td align="center" valign="middle"><a href="file.php?file=shirt.jpg"><img src="button.jpg" width="150" height="50" border="0" /></a></td> </tr> </table> |
file.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php if(isset($_GET['file'])) { $file=$_GET['file']; } else { # } header('Content-type: text/plain'); //open/save dialog box header('Content-Disposition: attachment; filename="'.$file.'"'); //read from server and write to buffer readfile($file); ?> |
DOWNLOAD