Skip to content

Instantly share code, notes, and snippets.

@geekgonecrazy
Created June 18, 2011 08:56
Show Gist options
  • Save geekgonecrazy/1032936 to your computer and use it in GitHub Desktop.
Save geekgonecrazy/1032936 to your computer and use it in GitHub Desktop.
<?php
//Download and hit counter script.
//@Author: Aaron Ogle
$file = $_GET['f'];
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'off');
// Prevent downloading any file
$file = str_replace(array("/", ".."), "", $file);
//set allowable extensions
$ext_filter = array("jar");
//get file extension
$file_extension = strtolower(substr(strrchr($file,"."),1));
if (!in_array($file_extension, $ext_filter)) {
exit('File Type Invalid');
} else if (!file_exists($file)) {
exit('File Does Not Exist');
}
//Set count +1
$count = @file_get_contents("count.txt");
$count++;
@file_put_contents('count.txt', $count);
@file_put_contents('hosts.html', gethostbyaddr($_SERVER['REMOTE_ADDR']) . '<br />', FILE_APPEND);
//do 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: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile("$file");
exit();
?>
@geekgonecrazy
Copy link
Author

Not reliable, file doesn't always download. Probably easier to just parse the log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment