<?php
session_start();
$here = 'http://marc2003.dyndns.org/ocuk/';
$files = 'files/';
$thumbs = 'thumbs/';
@mkdir($files);
@mkdir($thumbs);
function im($type, $b, $thumb) {
switch($type) {
case 'image/png':
case 'image/x-png':
imagepng($b, $thumb);
break;
case 'image/gif':
imagegif($b, $thumb);
break;
case 'image/jpeg':
case 'image/pjpeg':
imagejpeg($b, $thumb);
break;
}
imagedestroy($b);
}
if($_POST['upload']) {
$name = $_FILES['userfile']['name'];
$tmp_name = $_FILES['userfile']['tmp_name'];
$size = $_FILES['userfile']['size'];
$type = $_FILES['userfile']['type'];
$error = $_FILES['userfile']['error'];
switch($error) {
case 0:
switch($type) {
case 'image/png':
case 'image/x-png':
$im = imagecreatefrompng($tmp_name);
break;
case 'image/gif':
$im = imagecreatefromgif($tmp_name);
break;
case 'image/jpeg':
case 'image/pjpeg':
$im = imagecreatefromjpeg($tmp_name);
break;
default:
$_SESSION['message'] = 'sorry, that wasn\'t a valid file type. only jpg/png/gif files are allowed!';
}
while(file_exists($files.$rand.$name)) {
$rand = rand(1, 9999);
}
$name = $rand.$name;
if($im && move_uploaded_file($tmp_name, $files.$name)) {
$width = imagesx($im);
$height = imagesy($im);
$thumb = $thumbs.$name;
if(($width <= 200) && ($height <= 200)) {
im($type, $im, $thumb);
} else {
$ratio = $width/$height;
if ($ratio>1){
$newwidth = 200;
$newheight = 200/$ratio;
} else {
$newwidth = 200*$ratio;
$newheight = 200;
}
$new = imagecreatetruecolor($newwidth,$newheight + 15);
imagecopyresampled($new, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$white = imagecolorallocate($im, 255, 255, 255);
$text = $width.'x'.$height.' '.intval($size/1024).'KB';
imagestring($new, 2, 5, $newheight, $text, $white);
im($type, $new, $thumb);
}
} else {
$_SESSION['message'] = 'unable to process uploaded file!';
}
break;
case 1:
case 2:
$_SESSION['message'] = 'your file must be under 2mb!';
break;
case 3:
$_SESSION['message'] = 'unable to process uploaded file!';
break;
case 4:
$_SESSION['message'] = 'you didn\'t select a file!';
}
header("Location: $here");
exit;
}
if($_POST['delete']) {
$name = $_POST['name'];
unlink($files.$name);
unlink($thumbs.$name);
header("Location: $here");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {background-color: #E6E6FA; font-family: verdana, sans-serif; }
.main {margin-bottom: 5px; width: 750px; height: 25px; }
.thumbnail {float: left; width: 220px; height: 375px; margin-right: 28px; margin-bottom: 5px; padding: 5px; }
.main, .thumbnail {background-color: #F0F8FF; border-style: dotted solid; border-width: 1px; border-color: #999999; }
p { margin-top: 4px; margin-bottom: 4px; margin-left: 4px; margin-right: 4px; }
img { border: 0; }
</style>
</head>
<body>
<div class="main">
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<p style="margin-top: 1px; margin-bottom: 1px;">
<input name="MAX_FILE_SIZE" type="hidden" value="2000000">
<input name="userfile" type="file" size="40">
<input type="submit" name="upload" value="upload"></p>
</form>
</div>
<div style="width: 800px">
<?php
if($_SESSION['message']) {
echo '<div class="main"><p style="color: #FF0000;"><label> </label>'.$_SESSION['message']."</p></div>\n";
unset($_SESSION['message']);
}
$dh = opendir($files);
while (($name = readdir($dh)) !== false) {
if($name != "." && $name != "..") {
?>
<div style="text-align: center;" class="thumbnail">
direct link to full image -
<p><textarea style="width: 200px" rows="1" cols="2" readonly="readonly"><?php echo $here.$files.$name; ?></textarea></p>
thumbnail for forums -
<p><textarea style="width: 200px" rows="1" cols="2" readonly="readonly">[url=<?php echo $here.$files.$name; ?>][img]<?php echo $here.$thumbs.$name; ?>[/img][/url]</textarea></p>
<p style="height: 215px"><a href="<?php echo $here.$files.$name; ?>"><img src="<?php echo $here.$thumbs.$name; ?>" alt="<?php echo $name; ?>"></a></p>
<form action="" method="post" name="form">
<p><input type="hidden" name="name" value="<?php echo $name; ?>">
<input type="submit" name="delete" value="delete"></p>
</form>
</div>
<?php
}
}
closedir($dh);
?>
</div>
</body>
</html>