Created
June 22, 2022 06:23
-
-
Save davidperezgar/4f41b7de10d2e936e879f64c7ffa316d to your computer and use it in GitHub Desktop.
Revisions
-
davidperezgar created this gist
Jun 22, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <?php // --------------------------------- // File: download.php // Author: Jim Penaloza // Web: http://blog.unijimpe.net // --------------------------------- // verify file if (!isset($_GET['file']) || empty($_GET['file'])) { exit(); } // get filename $root = ""; $file = basename($_GET['file']); $path = $root.$file; $type = ''; /* Google Analytics */ include 'ss-ga.class.php'; $ssga = new ssga( 'UA-XXXXX-XXX', 'domain.com' ); $ssga->set_event( 'Category', 'Tag', $file, '10' ); $ssga->send(); if (is_file($path)) { $size = filesize($path); if (function_exists('mime_content_type')) { $type = mime_content_type($path); } else if (function_exists('finfo_file')) { $info = finfo_open(FILEINFO_MIME); $type = finfo_file($info, $path); finfo_close($info); } if ($type == '') { $type = "application/force-download"; } // Set Headers header("Content-Type: $type"); header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $size); // Download File readfile($path); } else { die("File not exist !!"); }