<?
echo '<?xml version="1.0" encoding="iso-8859-2"?>';
$allowed_files = array('jpg', 'jpeg', 'bmp', 'png', 'gif', 'dib', 'jpe', 'jfif', 'tif', 'tiff', '001', '2bp', '2d', '3d', '3d2', '3d4', '3da', '3df', '3dl', '3dm', '3dmf', '3ds', '3dv', '3dx', '8pbs', 'amb', 'ac5', 'ac6', 'acr', 'act', 'adc', 'adi', 'afp', 'agif', 'agp', 'ai', 'ais', 'amu', 'an8', 'anm', 'apng', 'ard', 'arr', 'art', 'asat', 'awd', 'bcf', 'bcp', 'bip', 'biz', 'blend', 'blkrt', 'blz', 'bmc', 'bmf', 'br3', 'br4', 'br5', 'bro', 'bvh', 'c4', 'c4d', 'cag', 'cal', 'cals', 'cam', 'can', 'catpart', 'cd2', 'cd5', 'cdr', 'cdt', 'ce', 'cel', 'cgm', 'cil', 'cin', 'cit', 'cld', 'cm2', 'cmp', 'cmx', 'cmz', 'cmv', 'comicdoc', 'cpc', 'cpt', 'cr2', 'crw', 'crz', 'csd', 'csf', 'csm', 'cut', );
$download_path = 'images/';
$max_file_size = 5242880;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
<title>
Upload.com
</title>
<style>
.error { color: red }
a { color: gray; text-decoration: none }
a:visited { color: gray; text-decoration: none }
a:hover { color: gray; text-decoration: underline }
</style>
</head>
<body>
<div align="center">
<a href="index.php">File list</a>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value=<?=$max_file_size?>/>
<input name="file" type="file" size="40"/><br />
<input type="submit" value="Send Your File"/>
</form>
<?
$tmp_file = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$extension = explode(".", $name);
$ext = end($extension);
if(is_uploaded_file($tmp_file)):
if(!in_array($ext, $allowed_files)):
echo '<span class="error">Not allowed extension.</span>';
return true;
endif;
$newname = createName($ext);
move_uploaded_file($tmp_file, $download_path.''.$newname);
echo '<strong><a href="download.php?file='.$newname.'">'.$newname.'</a></strong> (<strong>'.size($size).'</strong>) has been succesfully uploaded.';
endif;
function createName($extension)
{
$length = 6;
$pattern = 'ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
$max = strlen($pattern) - 1;
$random = '';
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++)
$random .= $pattern[mt_rand(0, $max)];
return $random.'.'.$extension;
}
function size($size)
{
$size = $size;
$s = 'b';
if($size >= 1073741824):
$size = $size / 1024 / 1024 / 1024;
$s = 'gb';
elseif($size >= 1048576):
$size = $size / 1024 / 1024;
$s = 'mb';
elseif($size >= 1024):
$size = $size / 1024;
$s = 'kb';
endif;
return round($size, 2).' '.$s;
}
?>
</div>
</body>
</html>