Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function ftransfer($downloadpath) {
- if (file_exists($downloadpath)) {
- set_time_limit(0);
- ini_set("memory_limit","512M");
- ini_set("max_input_time","20000");
- ini_set("max_execution_time","20000");
- $path_parts = pathinfo($downloadpath);
- $filename=$path_parts['basename'];
- header("Content-type: ".getmtype($downloadpath));
- header('Content-disposition: attachment; filename="'.$filename.'"');
- echo file_get_contents($downloadpath);
- exit;
- }
- else { die('Error: No such file ('.$downloadpath.')'); }
- exit;
- }
- function getmtype($file_path) {
- $mtype = '';
- if (function_exists('finfo_file')) {
- $finfo = finfo_open(FILEINFO_MIME); // return mime type
- $mtype = finfo_file($finfo, $file_path);
- finfo_close($finfo);
- }
- else if (function_exists('mime_content_type')) {
- $mtype = mime_content_type($file_path);
- }
- if ($mtype == '') {
- $mtype = "application/force-download";
- }
- return $mtype;
- }
Add Comment
Please, Sign In to add comment