Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getDownloads(){
- if (isset($_GET['theDLfile'])){
- $file = $_GET['theDLfile'];
- $upload_dir = wp_upload_dir();
- global $current_user;
- get_currentuserinfo();
- $url=$upload_dir['basedir'].'/file_uploads/'.$current_user->ID .'/';
- if (isset($_GET['page'])) {
- if ($_GET['page']=="manage-files-main") $url=$upload_dir['basedir'].'/file_uploads/'; // the user folder is in $file
- }
- $filename = $url.$file ;
- if (!file_exists($filename)) {
- die("file not found: ". $file);
- } else {
- $fileNM = str_replace(" ","_",$file);
- $file_extension = strtolower(substr(strrchr($filename,"."),1));
- switch ($file_extension) {
- case "pdf": $ctype="application/pdf"; break;
- case "exe": $ctype="application/octet-stream"; break;
- case "zip": $ctype="application/zip"; break;
- case "doc": $ctype="application/msword"; break;
- case "xls": $ctype="application/vnd.ms-excel"; break;
- case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
- case "gif": $ctype="image/gif"; break;
- case "png": $ctype="image/png"; break;
- case "jpe": case "jpeg":
- case "jpg": $ctype="image/jpg"; break;
- default: $ctype="application/force-download";
- }
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private",false);
- header("Content-Type: $ctype");
- header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
- header("Content-Transfer-Encoding: binary");
- header("Content-Length: ".@filesize($filename));
- set_time_limit(0);
- @readfile("$filename") or die("File not found.");
- }
- }
- return;
- }
Add Comment
Please, Sign In to add comment