Location: PHPKode > projects > Backend code/CMS for blizzle.com > v1.x/upload.php
<?
require "functions.php";




if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {


	if (!chkFileType($HTTP_POST_FILES['userfile']['name'])) {
		echo "file type not allowed";
	} else {

		if (!file_exists($doc_root."/files/".retUserName())) {
			$oldumask = umask(0);
			mkdir($doc_root."/files/".retUserName(),0777);
			echo "created dir";
			umask($oldumask);
		}

		if (!file_exists($doc_root."/files/".retUserName()."/".$HTTP_POST_FILES['userfile']['name'])) {
			if ($HTTP_POST_FILES['userfile']['size'] > 524288) {
				$flagged = 1;
			} else {
				$flagged = 0;
			}
			move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $doc_root."/files/".retUserName()."/".$HTTP_POST_FILES['userfile']['name']);
			$thumbnail = createThumbnail($doc_root."/files/".retUserName(),$HTTP_POST_FILES['userfile']['name'],250);
			$query = "INSERT INTO files (userid,filename,thumbnail,filesize,flagged,date,lastaccess,downloads,comments) VALUES(".retUserID().",'/files/".retUserName()."/".$HTTP_POST_FILES['userfile']['name']."','$thumbnail',".$HTTP_POST_FILES['userfile']['size'].",$flagged,NOW(),NOW(),0,'');";
			echo "<p>".$query."<p>";
			mysql_query ($query, $link) or die (mysql_error());
			echo "success.";
		} else {
			echo "file exists.";
		}
	}

} else {

	?>
		<form enctype="multipart/form-data" action="upload.php" method="post">
		<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
		Send this file: <input name="userfile" type="file">
		<input type="submit" value="Send File">
		</form>
	<?

}


function chkFileType($filename) {

	$types = array (".png",".gif",".jpg","jpeg",".psd",".psp",".tif","tiff",".bmp",".eps",".tga",".wmf",".mov",".avi",".rar",".zip",".exe",".swf",".htm","html",".pdf",".txt",".doc",".xml");
	$ext = strtolower(substr($filename,-4));
	return in_array ($ext, $types);

}

function createThumbnail($image_path,$image_name,$thumb_width) {
if (imagetypes() & IMG_JPG) {
	$ext = strtolower(substr($image_name,-4));
	$types = array (".jpg","jpeg");

	if (in_array ($ext, $types)) {
		$src_img = imagecreatefromjpeg("$image_path/$image_name");
		$origw=imagesx($src_img);
		$origh=imagesy($src_img);
		$new_w = $thumb_width;
		$diff=$origw/$new_w;
		$new_h=$new_w;
		$dst_img = imagecreate($new_w,$new_h);
		imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
		imagejpeg($dst_img, "$image_path/thm_$image_name");
		return "$image_path/thm_$image_name";
	} else {
		return "";
	}
} else {
return "";
}

} 


?>
Return current item: Backend code/CMS for blizzle.com