Location: PHPKode > scripts > SelectaPix Image Gallery > classes/upload.php
<?php
/* +----------------------------------------------------------------------+
   |SelectaPix Open Source Gallery	                                      |
   +----------------------------------------------------------------------+
   | Copyright (c) 2004 OutOfTheTrees			                          |
   |                                                                      |
   | http://www.outofthetrees.co.uk/index.php                             |
   | 												                      |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.0 of the GPL license,       |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.outofthetrees.co.uk/license/2_0.txt.                      |
   | If you did not receive a copy of the SelectaPix license and are 	  |
   | unable to obtain it through the world-wide-web, please send a note   |
   | to hide@address.com so we can mail you a copy immediately.|
   +----------------------------------------------------------------------+ */
if (!defined("ACCESS")) {
    die ("Direct request denied");
}

class ImageUpload {
	var $f;
	var $copy;
	var $picture_caption;
	var $thumb_name_location;
	var $image_name_location;

	function ImageUpload($f) {
		$this->f =& $f;
		$this->site_name = SITE_NAME;
		$this->site_path = SITE_PATH;
		$this->img_dir = IMAGE_DIR;
		$this->album_table = SQL_ABM_TBL;
		$this->image_table = SQL_IMG_TBL;
		$this->SetMaxPicSizeKb(MAX_PIC_SIZE_KB);
		$this->SetMaxThumbWidth(MAX_THUMB_WIDTH);
		$this->SetMaxThumbHeight(MAX_THUMB_HEIGHT);
		$this->SetMaxImageWidth(MAX_IMAGE_WIDTH);
		$this->SetMaxImageHeight(MAX_IMAGE_HEIGHT);
		$this->SetImageQuality(IMAGE_QUALITY);
		$this->SetMaxDescription(MAX_DESCRIPTION);
		$this->SetSiteName($this->site_name);
		$this->SetThumbDirectory($this->site_path.$this->img_dir);
		$this->SetImageDirectory($this->site_path.$this->img_dir);
	}

	function SetSiteName($newsite_name) {
    	$this->site_name = $newsite_name;
  	}
    function SetUploaderName($newuploader_name) {
    	$this->uploader_name = $newuploader_name;
  	}
  	function SetPictureCaption($newpicture_caption) {
  		$this->picture_caption = $newpicture_caption;
  	}
  	function SetMaxPicSizeKb($newmax_pic_size_kb) {
  		$this->max_pic_size_kb = $newmax_pic_size_kb;
  	}
  	function SetMaxThumbWidth($newmax_thumb_width) {
  		$this->max_thumb_width = $newmax_thumb_width;
  	}
  	function SetMaxThumbHeight($newmax_thumb_height) {
  		$this->max_thumb_height = $newmax_thumb_height;
  	}
  	function SetMaxImageWidth($newmax_image_width) {
  		$this->max_image_width = $newmax_image_width;
  	}
  	function SetMaxImageHeight($newmax_image_height) {
  		$this->max_image_height = $newmax_image_height;
  	}
  	function SetImageQuality($new_image_quality) {
  		$this->image_quality = $new_image_quality;
  	}
  	function SetThumbDirectory($newthumb_directory) {
  		$this->thumb_directory = $newthumb_directory;
  	}
  	function SetImageDirectory($newimage_directory) {
  		$this->image_directory = $newimage_directory;
  	}
  	function  SetMaxDescription($newmax_description) {
  		$this->max_description = $newmax_description;
  	}
  	function  SetAcceptableFileTypes($newacceptable_file_types) {
  		$this->acceptable_file_types = $newacceptable_file_types;
  	}
  	function  SetSubmitted($newsubmitted) {
  		$this->submitted = $newsubmitted;
  	}
  	function  SetMultiSubmitted($newmulti_submitted) {
  		$this->multi_submitted = $newmulti_submitted;
  	}
  	function  SetVisitorPhoto($newvisitorphoto) {
  		$this->visitorphoto = $newvisitorphoto;
  	}
  	function  SetVisitorPhotoName($newvisitorphoto_name) {
  		$this->visitorphoto_name = $newvisitorphoto_name;
  	}
  	function  SetVisitorPhotoSize($newvisitorphoto_size) {
  		$this->visitorphoto_size = $newvisitorphoto_size;
  	}
  	function  SetVisitorPhotoType($newvisitorphoto_type) {
  		$this->visitorphoto_type = $newvisitorphoto_type;
  	}
  	function SetDescription($newdescription) {
  		$this->description = $newdescription;
  	}
  	function  SetCurrentUrl($newcurrent_url) {
  		$this->current_url = $newcurrent_url;
  	}
  	function SetAlbumID($newalbumID) {
  		$this->albumID = $this->f->util->ForceInt($newalbumID, 0);
  	}
  	function  SetRequestType($newrequest_type) {
  		$this->request_type = $newrequest_type;
  	}
  	function SetReferer($newreferer) {
    	$this->referer = $newreferer;
  	}
  	function SetCaption($newcaption) {
    	$this->caption = $this->f->util->FormatStringForDatabaseInput($newcaption, 1);
  	}

	function create_single() {
		if($_SESSION['RoleLevel']>=4) {
  			$this->check_submitted();
  			if ($this->submitted) {
	  			$this->visitorphoto_name = ($_FILES[visitorphoto]['name']);
				$this->visitorphoto = ($_FILES[visitorphoto]['tmp_name']);
				$this->visitorphoto_size = ($_FILES[visitorphoto]['size']);
				$this->visitorphoto_type = ($_FILES[visitorphoto]['type']);
				$this->validate_input();
				$this->cleanup_inputs();
				$news = $this->create_images();
				$this->show_form($this->request_type, $news);
			}
			elseif ($this->request_type == "single") {
				$this->show_form($this->request_type);
			}
  		}
  		else {
  			$this->show_form($this->request_type);
  			exit();
  		}
	}

	function create_multiple() {
  		if($_SESSION['RoleLevel']>=4) {
	  		$this->check_submitted();
			if ($this->multi_submitted) {
				for($i=1; $i<=10; $i++) {
					$this->visitorphoto_name = ($_FILES[visitorphoto.$i]['name']);
					$this->visitorphoto = ($_FILES[visitorphoto.$i]['tmp_name']);
					$this->visitorphoto_size = ($_FILES[visitorphoto.$i]['size']);
					$this->visitorphoto_type = ($_FILES[visitorphoto.$i]['type']);
					if (!$this->visitorphoto || $this->visitorphoto == "none") {
						break;
					}
					$this->validate_input();
					$this->cleanup_inputs();
					$this->create_images();
				}
				$news = "<p class=\"goodnews\">The following images have been successfully uploaded:<br />".$_SESSION['uploaded']."<br /></p>";
				$_SESSION['uploaded'] = '';
				$this->show_form($this->request_type, $news);
			}
			elseif ($this->request_type == "multiple") {
				$this->show_form($this->request_type);
			}
		}
  		else {
  			$this->show_form($this->request_type);
  			exit();
  		}
	}

	function check_submitted() {
		if ($this->submitted == "true" && $_SESSION['RoleLevel'] <= 2) {
			do_html_heading("Problem");
			echo '<p class="badnews">You do not have sufficient administrative rights to perform this action</p>';
			$this->Show_Form($this->request_type);
			exit;
		}
		elseif ($this->submitted != "true" && $this->request_type != 'multiple') {
			$this->Show_Form($this->request_type);
			exit;
  		}
  		elseif ($this->submitted == "true" && $_SESSION['RoleLevel'] > 2) {
  			return $this->submitted = true;
  		}
		if ($this->multi_submitted == "true" && $_SESSION['RoleLevel'] <= 2) {
			do_html_heading("Problem");
			echo '<p class="badnews">You do not have sufficient administrative rights to perform this action</p>';
			$this->Show_Form($this->request_type);
			exit;
		}
  		elseif ($this->multi_submitted != "true" && $this->request_type != 'single') {
			$this->Show_Form($this->request_type);
			exit;
  		}
  		elseif ($this->multi_submitted == "true" && $_SESSION['RoleLevel'] > 2) {
  			return $this->multi_submitted = true;
  		}
	}

  	function validate_input() {
  		// Moron check - have they selected a file?
		if (!$this->visitorphoto || $this->visitorphoto == "none") {
			$this->upload_error(1);
		}
		// Is the file size OK?
		$this->check_upload_size($this->visitorphoto_size);
		// Security check
		if (!is_uploaded_file($this->visitorphoto)) {
			$this->upload_error(4);
		}
		// Is the file in the correct format?
		if (!eregi($this->acceptable_file_types, $this->visitorphoto_type)) {
			$this->upload_error(5);
		}
		//Is the name of the person uploading within acceptable parameters?
		if (strlen($this->uploader_name) > 30) {
			$this->upload_error(8);
		}
		//Is the description within acceptable parameters?
		if (strlen($this->description) > $this->max_description) {
			$this->upload_error(9);
		}
		//Have they selected a category?
		if ((!isset($this->albumID)) || ($this->albumID == 0)) {
			$this->upload_error(10);
		}
  	}

  	function cleanup_inputs() {
		$uploader_name = trim(ereg_replace("[^a-zA-Z0-9 -]", "", str_replace("%20", " ", $this->uploader_name)));
		$description = trim(htmlspecialchars(strip_tags($this->description)));
		$caption = trim(htmlspecialchars(strip_tags($this->caption)));

		// Clean up their file name (only lowercase letters, numbers and underscores)
		$visitorphoto_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", 	strtolower($this->visitorphoto_name))));

		// Remove the file extension
		$visitorphoto_name = explode(".", $visitorphoto_name);
		$visitorphoto_name = str_replace('.', '', $visitorphoto_name[0]);
		$_SESSION['visitorphoto_name'] = $visitorphoto_name;
	}

	function create_images() {
		// If file of same name exists, add incremental number
		while(file_exists($this->image_directory . $_SESSION['visitorphoto_name'] . $copy . ".jpg")) {
			$copy = $n;
			$n++;
		}

		$visitorphoto_name  = $_SESSION['visitorphoto_name'].$copy.".jpg";
		$thumb_name_location = $this->thumb_directory."tn_".$visitorphoto_name;
		$image_name_location = $this->image_directory.$visitorphoto_name;

		// Get dimensions of uploaded picture
		$size = GetImageSize($this->visitorphoto);
		$width = $size[0];
		$height = $size[1];

		// Calculate the height and width of thumbnail
		$this->calc_thumbsize($this->max_thumb_width, $this->max_thumb_height, $width, $height);

		// Calculate height and width of final large image
		$this->calc_imagesize($this->max_image_width, $this->max_image_height, $width, $height);

		// Copy original into new image and thumbnail
		$source = imagecreatefromjpeg($this->visitorphoto);
		$thumb_destination = imagecreatetruecolor($this->thumb_width, $this->thumb_height);
		imagecopyresampled($thumb_destination, $source, 0, 0, 0, 0, $this->thumb_width, $this->thumb_height, $width, $height);

		$image_destination = imagecreatetruecolor($this->image_width, $this->image_height);
		imagecopyresampled($image_destination, $source, 0, 0, 0, 0, $this->image_width, $this->image_height, $width, $height);

		if (!empty($this->picture_caption)) {
			$white = ImageColorAllocate ($image_destination, 255, 255, 255);
			ImageString($image_destination, 2, 8, 8, $this->picture_caption, $white);
		}

		if (!ImageJpeg($thumb_destination, $thumb_name_location, $this->image_quality)) {
			$this->upload_error(6);
		}

		else if (!ImageJpeg($image_destination, $image_name_location, $this->image_quality)) {
			$this->upload_error(7);
		}

		else {
			/**************************/
			/* 	PUT NEW IMAGE INTO DATABASE
				Variables to insert into database:
				$uploadername, $album, $caption, $description, $thumb_name_location, $image_name_location
			*/
			/**************************/
			$this->f->conn->query("INSERT INTO $this->image_table (imageID, uploadername, albumID, caption, image_url, description, upload_date) VALUES
						  		 ('', '$this->uploader_name', '$this->albumID', '$this->caption', '$visitorphoto_name', '$this->description', NOW())", 'none');
			if (!$this->f->conn->result) {
				echo "<p class=\"badnews\">Error! Unable to insert ".$visitorphoto_name." into database</p>";
			}

			if ($this->request_type == "single") {
				$news = '<p class="goodnews"><strong>Thanks ' . stripslashes($this->uploader_name) . '</strong><br />';
				$news .= $this->visitorphoto_name . ' was successfully uploaded to the site.<br />';
				$news .= 'Please use the form below if you would like to upload another picture.</p>';
			}
			elseif ($this->request_type == 'multiple') {
				$uploaded = $this->visitorphoto_name.", \n";
				$_SESSION['uploaded'] .= $uploaded;
			}
		}
		ImageDestroy($source);
		ImageDestroy($thumb_destination);
		ImageDestroy($image_destination);

		unlink($this->visitorphoto);
		return $news;
	}

function Show_Form($request_type, $news = '') {
	global $config;
	if ($request_type == 'single' || $this->request_type == 'single') {
		echo '<div id="breadcrumbtrail">';
		if(!isset($this->visitorphoto)) {
			echo "<a href=\"member.php\">Main Admin Area</a> &gt;&gt; <a href=\"".$this->referer."\">Return to Previous Page</a> &gt;&gt; Image Upload</div>\n\n";
		}
		else {
			echo "<a href=\"member.php\">Main Admin Area</a> &gt;&gt; Image Upload</div>\n\n";
		}
		echo '<div class="margins">';
?>
		<div id="uploadstatus">
		</div>

<?php
		echo "\n\n<h2>Upload a new image to ".$this->site_name."</h2>\n\n";
		echo @$news;
?>
		<form enctype="multipart/form-data" action="<?php echo $this->current_url.'?'.$_SERVER['QUERY_STRING']; ?>" method="post" onsubmit="showUploading(); return true" class="uploadform">
		<table border="0" cellspacing="0" summary="Form for adding new product and image">

		<tr>
		<td class="uploadleft" style="border-top: none;"><label for="uploadername">1. Enter your name:</label></td>
		<td style="border-top: none;"><input type="text" id="uploadername" name="uploadername" maxlength="30"
<?php
		if (isset($this->uploader_name)) {
			echo ' value="' . stripslashes($this->uploader_name) . '" ';
		}
		else {
			echo ' value="" ';
		}
		echo ' size="20" />';
?>
		</td>
		</tr>

		<tr>
		<td class="uploadleft"><label for="caption">2. Enter the Image Title:</label></td>
		<td><input type="text" id="caption" name="caption" maxlength="50" value="<?php echo stripslashes($this->caption); ?>" size="30" /></td>
		</tr>

		<tr>
		<td class="uploadleft"><label for="parent">3. Choose the album in which you wish the image to appear:</label></td>
		<td>
<?php
		if (!isset($_REQUEST['parentID'])) {
			echo "\n\t\t<select id=\"parentID\" name=\"parentID\" onchange=\"goLocation(this.form.parentID); return false;\">\n\t<option value=\"\">SELECT CATEGORY</option>\n";
		}
		else {
			echo "\n\t\t<select id=\"parentID\" name=\"parentID\" onchange=\"goLocation(this.form.parentID); return false;\">\n";
		}
		$row = $this->f->conn->query("SELECT albumID, album_name FROM $this->album_table WHERE parent_albumID = 0 ORDER BY album_name");
		for ($i=0; $i<count($row); $i++) {
			if(($_REQUEST['albumID']==$row[$i][albumID]) || ($_REQUEST['parentID']==$row[$i][albumID])) {
				echo "\t\t\t<option value=\"upload.php?parentID=".$row[$i][albumID]."&amp;request=single\" selected=\"selected\">".$row[$i][album_name]."</option>\n";
			}
			else {
				echo "\t\t\t<option value=\"upload.php?parentID=".$row[$i][albumID]."&amp;request=single\">".$row[$i][album_name]."</option>\n";
			}
		}
		$this->f->conn->freeResult();
?>
		</select></td>
		</tr>

		<tr>
		<td class="uploadleft"><label for="category">4. Choose the sub-album in which you wish the image to appear (leave blank for a top level album):</label></td>
		<td>
		<select id="albumID" name="albumID">
			<option value="">SELECT SUB-ALBUM</option>
<?php
		if($_REQUEST['parentID']==0) {
			$vars = $this->f->util->ForceInt($_REQUEST['albumID'], 0);
		}
		else {
			$vars = $this->f->util->ForceInt($_REQUEST['parentID'], 0);
		}

		$row = $this->f->conn->query("SELECT albumID, album_name FROM $this->album_table WHERE parent_albumID = $vars ORDER BY album_name");
		if(!empty($row)) {
			for ($i=0; $i<count($row); $i++) {
				if($_REQUEST['albumID']==$row[$i]['albumID']) {
					echo "\t\t\t<option value=\"".$row[$i][albumID]."\" selected=\"selected\">".$row[$i][album_name]."</option>\n";
				}
				else {
					echo "\t\t\t<option value=\"".$row[$i][albumID]."\">".$row[$i][album_name]."</option>\n";
				}
			}
		}
		$this->f->conn->freeResult();
?>
		</select></td>
		</tr>

		<tr>
		<td class="uploadleft"><label for="visitorphoto">5. Use the <em>Browse</em> button to find the picture* you want to upload from your computer:</label></td>
		<td><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo round($this->max_pic_size_kb * 1024); ?>" />
		<input name="visitorphoto" id="visitorphoto" type="file" accept="image/jpg, image/jpeg, image/pjpeg" />
		<input type="hidden" name="submitted" value="true" />
		<input type="hidden" name="request" value="<?php echo $this->request_type; ?>" /></td>
		</tr>

		<tr>
		<td colspan="2"><label for="description">6. Enter a short description of the image
		<div style="width: 500px; text-align: center;">
		<textarea name="description" id="description" style="width:100%" rows="15" cols="70">
<?php
		if(!empty($this->description)) {
			echo $this->description;
		}
		else {
			echo '&lt;p&gt;Replace with image description&lt;/p&gt;';
		}
		echo '</textarea>';
?>
		</div>
		</td>
		</tr>
		</table>

		<table border="0" cellspacing="0" summary="Form for adding new products and images, continued">
		<tr>
		<td class="uploadleft" style="border-top: none;"><label for="sendfile">7. Press the Upload Picture button <em>once</em> and wait for your photo to upload. This page will change once the process has been completed.</label></td>
		<td style="border-top: none;"><input type="submit" name="sendfile" id="sendfile" value="Upload Picture" class="button" /></td>
		</tr>
		</table>

		<div id="uploadstatus2"></div>
		</form>

<?php
	} // End of form for single image upload

	if($request_type == 'multiple' || $this->request_type == 'multiple') {
?>
		<div id="breadcrumbtrail">
<?php
		if(!isset($this->visitorphoto)) {
			echo "<a href=\"member.php\">Main Admin Area</a> &gt;&gt; <a href=\"".$this->referer."\">Return to Previous Page</a> &gt;&gt; Image Upload</div>\n\n";
		}
		else {
			echo "<a href=\"member.php\">Main Admin Area</a> &gt;&gt; Image Upload</div>\n\n";
		}
		echo '<div class="margins">';
?>
		<div id="uploadstatus">
		</div>
<?php
		echo "\n\t\t<h2>Upload images to the ".$this->site_name."</h2>\n\n";
		echo @$news;
?>
		<form enctype="multipart/form-data" action="<?php echo $this->current_url.'?'.$_SERVER['QUERY_STRING']; ?>" method="post" onsubmit="showUploading(); return true" class="uploadform">

		<table border="0" cellspacing="0" summary="Form for adding new products and images">

		<tr>
		<td class="uploadleft"><label for="uploadername">1. Enter your name:</label></td>
		<td><input type="text" id="uploadername" name="uploadername" maxlength="20"
<?php
		if (isset($this->uploader_name)) {
				echo ' value="' . stripslashes($this->uploader_name) . '" ';
		}
		echo 'size="20" />';
?>
		</td>
		</tr>


		<tr>
		<td class="uploadleft"><label for="parent">2. Choose the album in which you wish the image to appear:</label></td>
		<td>
<?php
		if (!isset($_REQUEST['parentID'])) {
			echo "\n\t\t<select id=\"parentID\" name=\"parentID\" onchange=\"goLocation(this.form.parentID); return false;\">\n\t<option value=\"\">SELECT CATEGORY</option>\n";
		}
		else {
			echo "\n\t\t<select id=\"parentID\" name=\"parentID\" onchange=\"goLocation(this.form.parentID); return false;\">\n";
		}
		$row = $this->f->conn->query("SELECT albumID, album_name FROM $this->album_table WHERE parent_albumID = 0 ORDER BY album_name");
		for ($i=0; $i<count($row); $i++) {
			if(($_REQUEST['albumID']==$row[$i][albumID]) || ($_REQUEST['parentID']==$row[$i][albumID])) {
				echo "\t\t\t<option value=\"upload.php?parentID=".$row[$i][albumID]."&amp;request=multiple\" selected=\"selected\">".$row[$i][album_name]."</option>\n";
			}
			else {
				echo "\t\t\t<option value=\"upload.php?parentID=".$row[$i][albumID]."&amp;request=multiple\">".$row[$i][album_name]."</option>\n";
			}
		}
		$this->f->conn->freeResult();
?>
		</select></td>
		</tr>

		<tr>
		<td class="uploadleft"><label for="album">3. Choose the sub-album in which you wish the image to appear (leave blank for top level albums):</label></td>
		<td>
		<select id="albumID" name="albumID">
			<option value="">SELECT SUB-ALBUM</option>
<?php
		if($_REQUEST['parentID']=='0') {
			$vars = $_REQUEST['albumID'];
		}
		else {
			$vars = $_REQUEST['parentID'];
		}

		$row = $this->f->conn->query("SELECT albumID, album_name FROM $this->album_table WHERE parent_albumID = $vars ORDER BY album_name");
		if(!empty($row)) {
			for ($i=0; $i<count($row); $i++) {
				if($_REQUEST['albumID']==$row[$i][albumID]) {
					echo "\t\t\t<option value=\"".$row[$i][albumID]."\" selected=\"selected\">".$row[$i][album_name]."</option>\n";
				}
				else {
					echo "\t\t\t<option value=\"".$row[$i][albumID]."\">".$row[$i][album_name]."</option>\n";
				}
			}
		}
		$this->f->conn->freeResult();
?>
		</select></td>
		</tr>
		<tr>
		<td colspan="2"><label for="visitorphoto1">4. Use the <strong>Browse</strong> buttons to find the pictures* you want to upload from your computer:</label>
		<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo round($this->max_pic_size_kb * 1024); ?>" /></td>
		</tr>

		<tr><td colspan="2" style="text-align: center;">
		<input type="file" id="visitorphoto1" name="visitorphoto1" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto2" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto3" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto4" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto5" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto6" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto7" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto8" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto9" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>
		<tr><td colspan="2" style="text-align: center;">
		<input type="file" name="visitorphoto10" accept="<?php $this->acceptable_file_types ?>" size="20" />
		</td></tr>

		<tr>
		<td class="uploadleft"><label for="sendfile">5. Press the Upload Pictures button <em>once</em> and wait for your photo(s) to upload. This page will change once the process has been completed &#8212; this may take a few minutes depending
		on the number of images you are uploading, their file sizes, and your connection speed.</label></td>
		<td><input type="hidden" name="multi_submitted" value="true" />
		<input type="hidden" name="request" value="<?php echo $this->request_type; ?>" />
		<input type="submit" id="sendfile" name="sendfile" value="Upload Pictures" class="button" /></td>
		</tr>

		</table>

		<div id="uploadstatus2"></div>

		</form>
<?php
	} // End of multiple images upload form
?>
	<div class="formrow">* Please note that photos must be in <?php echo $this->acceptable_file_types; ?> format(s), measure no more than 1024 x 768 pixels, and be under <?php echo $this->max_pic_size_kb; ?>kb in size.</div>

	</div>
<?php
	do_html_footer('7');
}

function check_upload_size($visitorphoto_size) {
	if ($visitorphoto_size == 0) {
		$this->upload_error(2);
	}
	if ($visitorphoto_size > round($this->max_pic_size_kb * 1024)) 	{
		$this->upload_error(3);
	}
}

function upload_error($problem) {

	echo '<p class="badnews"><strong>There was a problem uploading your photo:</strong><br />';

	switch($problem) {
	  case "1" :
		echo 'You probably neglected to choose a picture to upload.';
		echo ' You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "2" :
		echo 'Either you did not upload a picture, or you uploaded an empty file.';
		echo ' You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "3" :
		echo 'Your picture exceeds the file size limit of ' . $this->max_pic_size_kb . 'kb. ';
		echo 'We suggest you resize the picture or increase its compression ';
		echo 'in your image editing software before trying again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "4" :
	  	$result_unreg = session_unregister('valid_user');
		$result_dest = session_destroy();
		echo 'Possible file upload attack detected! ';
		if($result_dest) {
			echo 'You have been logged out of the system, ';
		}
		echo 'your IP address has been recorded, and we will ';
		echo 'be sending the boys round to teach you some respect.</p>';
		echo '</body></html>';
		break;
	  case "5" :
		echo 'Your browser did not send the correct MIME type for the uploaded file. ';
		echo 'Only images in ' . $this->acceptable_file_types . ' format can be uploaded. ';
		echo 'You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "6" :
		echo 'The thumbnail was not created. ';
		echo 'You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "7" :
		echo 'The image was not created. ';
		echo 'You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "8" :
		echo 'The name you entered was too long (max 30 characters). ';
		echo 'Please correct this and try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "9" :
		echo 'The description you entered was too long. ';
		echo 'Please correct this and try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  case "10" :
		echo 'You did not select an album for the image to appear in. ';
		echo 'Please correct this and try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	  default :
		echo 'An unknown error occurred. You may use the form below to try again.</p>';
		$this->Show_Form($this->request_type);
		break;
	}
	exit;
}

	function calc_thumbsize($max_thumb_width, $max_thumb_height, $width, $height) {

		$thumb_x_ratio = $this->max_thumb_width / $width;
		$thumb_y_ratio = $this->max_thumb_height / $height;

		if (($width <= $this->max_thumb_width) && ($height <= $this->max_thumb_height))	{
			$this->thumb_width = $width;
			$this->thumb_height = $height;
		}
		else if (($thumb_x_ratio * $height) < $this->max_thumb_height) {
			$this->thumb_height = ceil($thumb_x_ratio * $height);
			$this->thumb_width = $max_thumb_width;
		}
		else {
			$this->thumb_width = ceil($thumb_y_ratio * $width);
			$this->thumb_height = $this->max_thumb_height;
		}
	}

	function calc_imagesize($max_image_width, $max_image_height, $width, $height) {
		$image_x_ratio = $this->max_image_width / $width;
		$image_y_ratio = $this->max_image_height / $height;

		if (($width <= $this->max_image_width) && ($height <= $this->max_image_height)) {
 			$this->image_width = $width;
			$this->image_height = $height;
		}
		elseif (($image_x_ratio * $height) < $this->max_image_height) {
			$this->image_height = ceil($image_x_ratio * $height);
			$this->image_width = $this->max_image_width;
		}
		else {
			$this->image_width = ceil($image_y_ratio * $width);
			$this->image_height = $this->max_image_height;
		}
	}
	function extract_parentID($input) {
		$stage1 = explode('&', $input);
		$stage2 = explode('=', $stage1[0]);
		$this->SetAlbumID($stage2[1]);
	}
}
?>
Return current item: SelectaPix Image Gallery