Current Path : /web/htdocs/www.entinoprofit.org/home/admin/upload/
Upload File :
Current File : /web/htdocs/www.entinoprofit.org/home/admin/upload/upload.php

<?php
require ('../include/ImageEditor.php');
include_once("../include/config.php");
include_once("../include/auth.lib.php");


	if (isset($_POST["PHPSESSID"])) {
		session_id($_POST["PHPSESSID"]);
	}
	session_start();

	// The Demos don't save files
		$document = $_FILES['Filedata']['name'];
		$pic = urldecode(basename($_FILES["Filedata"]["name"]));
		$pic = ereg_replace("[^A-Za-z0-9.]", "", $pic);

		$random = rand(1111,9999);
		$nome = $document;
		//------ exact dimensions for normal image used in FIG ------//
		$normal_width = 800;
		$normal_height = 600;
		
		$thumb_width = 100;
		$thumb_height = 75;

		//how thumbs should be processed
		// full - a basic thumbnail
		// crop - crops thumbnail to fit
		$process = $_SESSION['thumbs'];

		$normal_ratio = round($normal_width/$normal_height, 2);
		$thumb_ratio = round($thumb_width/$thumb_height, 2);

		$mydir = '/web/htdocs/www.entinoprofit.org/home/gallery/foto/'.$_POST["FOLDER"].'/'; 
		$mydir_thumb = '/web/htdocs/www.entinoprofit.org/home/gallery/foto/'.$_POST["FOLDER"].'/tn/'; 
		
		if(isset($_FILES['Filedata']) && $_FILES['Filedata']['size']) { 


		if(move_uploaded_file ($_FILES['Filedata']['tmp_name'], $mydir.$nome)){
			list($width, $height, $type, $attr) = getimagesize($mydir.$nome);
			//get ratio of width/height
			$ratio = round($width/$height, 2);

			    //make a basic normal image
				if($ratio > $normal_ratio){
					//picture is too wide so we will set the the width to its maximum
					$new_width = $normal_width;
					$new_height = ceil(($normal_width*$height)/$width);
				} elseif($ratio < $thumb_ratio){
					//picture is too high so we will set the height to its maximum
					$new_width = ceil(($normal_height*$width)/$height);
					$new_height = $normal_height;
				} else {
					//the ratio of the image is the same as the thumbnail
					$new_width = $normal_width;
					$new_height = $normal_height;
				}
				
				//time to resize the image and crop it for thumbnail
				$imageEditor = new ImageEditor($nome, $mydir);
				//resize
				$imageEditor->resize($new_width, $new_height);
				//save
				$imageEditor->outputFile($nome, $mydir);
				
				
				
				//make a basic normal image
				if($ratio > $thumb_ratio){
					//picture is too wide so we will set the the width to its maximum
					$new_width = $thumb_width;
					$new_height = ceil(($thumb_width*$height)/$width);
				} elseif($ratio < $thumb_ratio){
					//picture is too high so we will set the height to its maximum
					$new_width = ceil(($thumb_height*$width)/$height);
					$new_height = $thumb_height;
				} else {
					//the ratio of the image is the same as the thumbnail
					$new_width = $thumb_width;
					$new_height = $thumb_height;
				}
				
				//time to resize the image and crop it for thumbnail
				$imageEditor = new ImageEditor($nome, $mydir);
				//resize
				$imageEditor->resize($new_width, $new_height);
				//save
				$imageEditor->outputFile($nome, $mydir_thumb);
			}
			
			



//		$query = "INSERT INTO documenti (club,idsocio,name) VALUES ('".$user["username"]."','".$_SESSION['id']."','$nome')";
//		$result = mysql_query($query) or die ("Errore");

		} 

	// In this demo we trigger the uploadError event in SWFUpload by returning a status code other than 200 (which is the default returned by PHP)
//	if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
//		// Usually we'll only get an invalid upload if our PHP.INI upload sizes are smaller than the size of the file we allowed
//		// to be uploaded.
//		header("HTTP/1.1 500 File Upload Error");
//		if (isset($_FILES["Filedata"])) {
//			echo $_FILES["Filedata"]["error"];
//		}
//		exit(0);
//	}
//	
//	echo "Make sure Flash Player on OS X works";

?>