Sure here is what I have now...
PHP Code:
<?php
define ("MAX_SIZE","204800");
define ("WIDTH","720");
define ("HEIGHT","720");
function make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
imagedestroy($dst_img);
imagedestroy($src_img);
}
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);
if ($sizekb > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="xxxxx/xxxx/xxxx/x/xxx/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
$thumb_name='xxxxx/xxxx/xxxx/x/xxx/'.$image_name;
$thumb=make_thumb($newname,$thumb_name,160,120);
}} }}
if(isset($_POST['Submit']) && !$errors)
{
echo "<center><h2>Your image has been submitted and will be reviewed by our administrators for approval</h2></center>";
echo '<a href="'.$newname.'"rel="lightbox" title="<strong>Your Submission Image</strong>"> <img src="'.$thumb_name.'"></a>';
}
?>
HTML Code:
<p>So you are thinking about uploading an image to our database and have it featured on our homepage. Please read and understand rules before uploading an image. </p>
<p><strong>RULES:</strong><br>
1. File format must be JPG, JPEG, PNG.<br>
2. Files may not be any larger than 200 KB (204,800 bytes).<br>
3. Images are at least 160 pixels, and no more than 720 pixels on each side.<br>
4. You are willing to display your image on our site and understand that anything uploaded to the internet could be stolen </p>
<form name="newad" method="post" enctype="multipart/form-data" action="" onSubmit="submitonce(this)">
<input name="understand" type="checkbox" id="understand" value="checkbox">
I have read and understood the rules.(*required)<br>
<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload Image"></td></tr>
</table>
</form>
Bookmarks