Paste: getwad

Author: herpppadrp
Mode: php
Date: Thu, 16 Feb 2012 03:21:42
Plain Text |
<?php
define('ZIP_DIRECTORY',	'.');

function ends_with($mainstr, $suffix)
{
	$n1 = strlen($mainstr);
	$n2 = strlen($suffix);
	if ($n1 < $n2)
		return 0;
	if (strcmp($suffix, substr($mainstr,$n1-$n2)) == 0 )
		return 1;
	return 0;
}

function file_exists_case($dir, $fname)
{
	$found = '';
	if ( $dh=opendir($dir) )
	{
		while ( ($file=readdir($dh)) !== false)
		{
			if ($file[0] == '.')
				continue;
			if (strcasecmp($file,$fname)==0)
			{
				$found = $dir . '/' . $file;
				break;
			}
		}
		closedir($dh);
	}
	return $found;
}

$fname = strtolower(substr($_SERVER['PATH_INFO'],1));
$n = strlen($fname);
if ($n > 0)
{
	if (!ends_with($fname,'.zip'))
		$fname .= '.zip';
	$full_name = file_exists_case(ZIP_DIRECTORY, $fname);
	if (strlen($full_name)>0)
	{
		header("Content-Type: application/octet-stream");
		header("Content-Length: " . filesize($full_name));
		header('Content-Disposition: attachment; filename="'. $fname . '"');
		readfile($full_name);
		exit;
	}
}
header('HTTP/1.0 404 Not Found');
?>

New Annotation

Summary:
Author:
Mode:
Body: