if (isset($_GET['file'])) { $file = base64_decode($_GET['file']); $download_file = unserialize($file); $fullPath = $download_file['filename']; $filename = $download_file['download_name']; $fileview = isset($download_file['view']) ? true : false; // Download process $extension = strtolower(pathinfo($fullPath, PATHINFO_EXTENSION)); // if (in_array($extension, array("pdf", "mp3", "mp4"))) { if (file_exists($fullPath)) { if ($fileview === false) { if ($fd = fopen($fullPath, "r")) { $fileSize = filesize($fullPath); switch ($extension) { case "pdf": $contentType = "application/pdf"; break; case "exe": $contentType = "application/octet-stream"; break; case "zip": $contentType = "application/zip"; break; case "doc": $contentType = "application/msword"; break; case "xls": $contentType = "application/vnd.ms-excel"; break; case "ppt": $contentType = "application/vnd.ms-powerpoint"; break; case "gif": $contentType = "image/gif"; break; case "png": $contentType = "image/png"; break; case "jpeg": case "jpg": $contentType = "image/jpg"; break; default: $contentType = "application/force-download"; break; } header("Content-type: $contentType"); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); // use 'attachment' to force a download header("Content-length: $fileSize"); header("Cache-control: private"); //use this to open files directly while (!feof($fd)) { $buffer = fread($fd, $fileSize); echo $buffer; } } } else { header("Content-type: application/pdf"); // Send the file to the browser. readfile($fullPath); } fclose($fd); die; } else { header('location: ' . $_SERVER['HTTP_REFERER']); die(); } } else { header('location: ' . $_SERVER['HTTP_REFERER']); die(); } /* } else { header('location: ' . $_SERVER['HTTP_REFERER']); die(); } */ ?>