Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_GET['FileName']))
- {
- $fullPath = $MainDirectory.$_GET['FileName'];
- if ($fd = fopen ($fullPath, "r")) {
- $fsize = filesize($fullPath);
- $path_parts = pathinfo($fullPath);
- if(isset($path_parts["extension"]))
- {
- $ext = strtolower($path_parts["extension"]);
- }
- else
- {
- $ext="";
- }
- switch ($ext) {
- case "pdf":
- $mime_type ="application/pdf";
- break;
- case "txt":
- $mime_type ="force-download";
- break;
- default:
- $mime_type="application/force-download";
- break;
- }
- header("Content-type: ".$mime_type);
- header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
- header("Content-Transfer-Encoding: binary");
- header("Accept-Ranges: bytes");
- header("Content-length: $fsize");
- header("Cache-control: private"); //use this to open files directly
- while(!feof($fd)) {
- $buffer = fread($fd, 2048);
- echo $buffer;
- }
- }
- fclose ($fd);
- }
- ?>
Add Comment
Please, Sign In to add comment