Question : php upload file understanding

I'm trying to figure out the below upload script that I'm using with SWFUpload.  I don't see where it's actually storing the files in the directory.  The reason why I want to figure this out is that I want to resize the image files before they're stored in the directory, any ideas on how to access the collection of files.  This is a multi-file upload script.  It does upload the files, so I know its working.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
<?php
	#	SWFUpload Email Notify
		# SWFUpload upload.php with simple file saving and email reporting
		# by Eric Pecoraro ( eric dot pecoraro at shepard dot com )
		# ***USE AT YOUR OWN RISK***  ***NO WARRENTIES EXPRESSED OR IMPLIED***
		# THIS SCRIPT WAS *NOT* WRITTEN FOR SECURITY, BUT RATHER AS SIMPLE PHP UPLOAD IMPLEMENTATION.
		# FEEL FREE TO USE/CHANGE/MODIFY/REDISTRIBUTE. Please notify me with improvements.
		# Developed as sample to be used in conjunction with SWFUpload (http://www.swfupload.org)
		# ABSTRACT
		# Saves SWFUpload uploaded files to a directory and intelligently reports on the process via email. 
		# SIMPLE SETUP, UP & RUNNING IN A FEW MINUTES
		# 1. Replace the original "upload.php" files from the SWFUpload v2.1.0 package with this file.
		# 2. Assign your email address to $upload_notify_email below.
		# 3. Create a PHP writable "uploads" directory as follows: swfupload/demos/uploads
	#	Setup SWFUpload Email Notify
	#	---------------	
		$upload_email_reporting = true ; 	// true or false (false turns email reporting off)
		$upload_notify_email = '[email protected]' ;  	// enter your valid email address
		$upload_directory = '/home/swfupload/uploads' ; // leave blank for default
		# DEFINING $upload_directory
		# Must point to a PHP writable directory
		# See http://www.onlamp.com/pub/a/php/2003/02/06/php_foundations.html for dealing with PHP permissions
		/*
		The default directory for this script is set to "uploads" directory 
		in the same directory as the index.php of the SWFUpload demo files:
			# SWFUpload v2.1.0 Beta.zip (SWFUpload package)
				# swfupload/demos/uploads
		This 'uploads' directory may not exist with the SWFUploads package and may need created (with PHP write permissions).
		In any case, this script will send an email message concerning the status of the upload directory.
		*/
	#	PHP Email Configuration Test
	#	---------------	
		# Set to "true" to test if your server's PHP mail() function configuration works, by attempting to upload one file.
		# A simple email will be sent per upload attempt, letting you know PHP's mail() funciton is working.
		$test_php_mail_config = false ; // true or false
	#	---------------
	#	NO MODIFICATIONS REQUIRED BELOW THIS LINE
	#	---------------
	#	CREATE DEFAULT UPLOAD DIRECTY LOCATION
	#	---------------	
		If ( !$upload_directory ) {
			$upload_directory = 'uploads' ; 
			$parent_dir = array_pop(explode(DIRECTORY_SEPARATOR, dirname(__FILE__)));
			$upload_directory = substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen($parent_dir) ) . $upload_directory ; 
		}
	#	---------------	
	#	EMAIL TESTS
		If ( !$upload_notify_email ) {
			$upload_email_reporting = false ;
		}
		# Sends one email per SWFUpload attempt. 
		if ( $test_php_mail_config == true ) {
			send_mail("SWFUpload Email Test: SUCCESS!",'Be sure to set $test_php_mail_config back to false so that SWFUpload Email Notify reporting is turned on.'); 
			$upload_email_reporting = false ;
		}
	#	---------------	
	#	TEST UPLOAD DIRECTORY
		If ( !file_exists($upload_directory) ) {	
			$msg = "The assigned SWFUpload directory, \"$upload_directory\" does not exist."; 
			send_mail("SWFUpload Directory Not Found: $upload_directory",$msg);
			$upload_email_reporting = false ;
		}
		if ( $upload_email_reporting == true ) {
			$uploadfile = $upload_directory. DIRECTORY_SEPARATOR . basename($_FILES['Filedata']['name']);   
			if ( !is_writable($upload_directory) ) {
				$msg = "The directory, \"$upload_directory\" is not writable by PHP. Permissions must be changed to upload files."; 
				send_mail("SWFUpload Directory Unwritable: $upload_directory",$msg);
				$upload_directory_writable = false ;
			} else {
				$upload_directory_writable = true ;
			}
		}
	// Work-around for setting up a session because Flash Player doesn't send the cookies
	if (isset($_POST["PHPSESSID"])) {
		session_id($_POST["PHPSESSID"]);
	}
	session_start();
	if ( !isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
		#	---------------	
		#	UPLOAD FAILURE REPORT
			if ( $upload_email_reporting == true ) {
				switch ($_FILES['Filedata']["error"]) {	
					case 1: $error_msg = 'File exceeded maximum server upload size of '.ini_get('upload_max_filesize').'.'; break;
					case 2: $error_msg = 'File exceeded maximum file size.'; break;
					case 3: $error_msg = 'File only partially uploaded.'; break;
					case 4: $error_msg = 'No file uploaded.'; break; 
				}
				send_mail("SWFUpload Failure: ".$_FILES["Filedata"]["name"],'PHP Error: '.$error_msg."\n\n".'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
			}
		echo "There was a problem with the upload";
		exit(0);
	} else {
		#	---------------	
		#	COPY UPLOAD SUCCESS/FAILURE REPORT
			if ( $upload_email_reporting == true AND $upload_directory_writable == true ) {
				if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
				 send_mail("SWFUpload File Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
				}else{
				 send_mail("SWFUpload File Not Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
				}
			}
		echo "Flash requires that we output something or it won't fire the uploadSuccess event";
	}
	#	---------------	
	#	MAIL FUNCTION
		function send_mail($subject="Email Notify",$message="") { 
			global $upload_notify_email ; 
			$from = '[email protected]' ; 
			$return_path = '-f '.$from ;
			mail($upload_notify_email,$subject,$message,"From: $from\nX-Mailer: PHP/ . $phpversion()");
		}
?>

Answer : php upload file understanding

Try the code below
To get working this code, the GD module must be enabled to can resize the image

there is a new function wich get a file and resize it, with the new width and height
if width or height is set to 0 (zero), then the function will mantain the aspect ratio

This is the code, where the function is called:
      //HERE IS THE CALL
      $newHeight = 100;
      $$newWidth = 100;
      resizeImage ($uploadfile, $uploadfile, $newHeight, $newWidth);

the var $uploadfile has the path of the file, the 2 first arguments are source and destination
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
<?php
        #       SWFUpload Email Notify
                # SWFUpload upload.php with simple file saving and email reporting
                # by Eric Pecoraro ( eric dot pecoraro at shepard dot com )
                # ***USE AT YOUR OWN RISK***  ***NO WARRENTIES EXPRESSED OR IMPLIED***
                # THIS SCRIPT WAS *NOT* WRITTEN FOR SECURITY, BUT RATHER AS SIMPLE PHP UPLOAD IMPLEMENTATION.
                # FEEL FREE TO USE/CHANGE/MODIFY/REDISTRIBUTE. Please notify me with improvements.
                # Developed as sample to be used in conjunction with SWFUpload (http://www.swfupload.org)
                # ABSTRACT
                # Saves SWFUpload uploaded files to a directory and intelligently reports on the process via email. 
                # SIMPLE SETUP, UP & RUNNING IN A FEW MINUTES
                # 1. Replace the original "upload.php" files from the SWFUpload v2.1.0 package with this file.
                # 2. Assign your email address to $upload_notify_email below.
                # 3. Create a PHP writable "uploads" directory as follows: swfupload/demos/uploads
        #       Setup SWFUpload Email Notify
        #       --------------- 
                $upload_email_reporting = true ;        // true or false (false turns email reporting off)
                $upload_notify_email = '[email protected]' ;       // enter your valid email address
                $upload_directory = '/home/swfupload/uploads' ; // leave blank for default
                # DEFINING $upload_directory
                # Must point to a PHP writable directory
                # See http://www.onlamp.com/pub/a/php/2003/02/06/php_foundations.html for dealing with PHP permissions
                /*
                The default directory for this script is set to "uploads" directory 
                in the same directory as the index.php of the SWFUpload demo files:
                        # SWFUpload v2.1.0 Beta.zip (SWFUpload package)
                                # swfupload/demos/uploads
                This 'uploads' directory may not exist with the SWFUploads package and may need created (with PHP write permissions).
                In any case, this script will send an email message concerning the status of the upload directory.
                */
        #       PHP Email Configuration Test
        #       --------------- 
                # Set to "true" to test if your server's PHP mail() function configuration works, by attempting to upload one file.
                # A simple email will be sent per upload attempt, letting you know PHP's mail() funciton is working.
                $test_php_mail_config = false ; // true or false
        #       ---------------
        #       NO MODIFICATIONS REQUIRED BELOW THIS LINE
        #       ---------------
        #       CREATE DEFAULT UPLOAD DIRECTY LOCATION
        #       --------------- 
                If ( !$upload_directory ) {
                        $upload_directory = 'uploads' ; 
                        $parent_dir = array_pop(explode(DIRECTORY_SEPARATOR, dirname(__FILE__)));
                        $upload_directory = substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen($parent_dir) ) . $upload_directory ; 
                }
        #       --------------- 
        #       EMAIL TESTS
                If ( !$upload_notify_email ) {
                        $upload_email_reporting = false ;
                }
                # Sends one email per SWFUpload attempt. 
                if ( $test_php_mail_config == true ) {
                        send_mail("SWFUpload Email Test: SUCCESS!",'Be sure to set $test_php_mail_config back to false so that SWFUpload Email Notify reporting is turned on.'); 
                        $upload_email_reporting = false ;
                }
        #       --------------- 
        #       TEST UPLOAD DIRECTORY
                If ( !file_exists($upload_directory) ) {        
                        $msg = "The assigned SWFUpload directory, \"$upload_directory\" does not exist."; 
                        send_mail("SWFUpload Directory Not Found: $upload_directory",$msg);
                        $upload_email_reporting = false ;
                }
                if ( $upload_email_reporting == true ) {
                        $uploadfile = $upload_directory. DIRECTORY_SEPARATOR . basename($_FILES['Filedata']['name']);   
                        if ( !is_writable($upload_directory) ) {
                                $msg = "The directory, \"$upload_directory\" is not writable by PHP. Permissions must be changed to upload files."; 
                                send_mail("SWFUpload Directory Unwritable: $upload_directory",$msg);
                                $upload_directory_writable = false ;
                        } else {
                                $upload_directory_writable = true ;
                        }
                }
        // Work-around for setting up a session because Flash Player doesn't send the cookies
        if (isset($_POST["PHPSESSID"])) {
                session_id($_POST["PHPSESSID"]);
        }
        session_start();
        if ( !isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
                #       --------------- 
                #       UPLOAD FAILURE REPORT
                        if ( $upload_email_reporting == true ) {
                                switch ($_FILES['Filedata']["error"]) { 
                                        case 1: $error_msg = 'File exceeded maximum server upload size of '.ini_get('upload_max_filesize').'.'; break;
                                        case 2: $error_msg = 'File exceeded maximum file size.'; break;
                                        case 3: $error_msg = 'File only partially uploaded.'; break;
                                        case 4: $error_msg = 'No file uploaded.'; break; 
                                }
                                send_mail("SWFUpload Failure: ".$_FILES["Filedata"]["name"],'PHP Error: '.$error_msg."\n\n".'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
                        }
                echo "There was a problem with the upload";
                exit(0);
        } else {
                #       --------------- 
                #       COPY UPLOAD SUCCESS/FAILURE REPORT
                        if ( $upload_email_reporting == true AND $upload_directory_writable == true ) {
                                if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {

				//HERE IS THE CALL
				$newHeight = 100;
				$$newWidth = 100;
				resizeImage ($uploadfile, $uploadfile, $newHeight, $newWidth);

					
                                 send_mail("SWFUpload File Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
                                }else{
                                 send_mail("SWFUpload File Not Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true)); 
                                }
                        }
                echo "Flash requires that we output something or it won't fire the uploadSuccess event";
        }
        #       --------------- 
        #       MAIL FUNCTION
                function send_mail($subject="Email Notify",$message="") { 
                        global $upload_notify_email ; 
                        $from = '[email protected]' ; 
                        $return_path = '-f '.$from ;
                        mail($upload_notify_email,$subject,$message,"From: $from\nX-Mailer: PHP/ . $phpversion()");
                }


	function resizeImage ($src, $dest, $newHeight, $newWidth) 
	{ 
		if ( $dest ) 
			fopen($dest, "w") || die("Imposible crear Previa $dest. Chequear permisos del directorio!"); 
		$imgInfo = getimagesize($src); $width = $imgInfo[0]; $height = $imgInfo[1]; 
	    $file_type = $imgInfo[2]; 
    	if ( $newHeight || $newWidth ) 
			if ( $newHeight && $newWidth ) 
			{ 
				$width = $newWidth; 
				$height = $newHeight; 
			}
			else 
				if ( $newWidth == "0" ) 
				{ 
					$ratio = (intval(($width / $newHeight) * 100)) / 100;  
					$width = (intval(($width / $ratio) * 100)) / 100; 
					$height = (intval(($height / $ratio) * 100)) / 100; 
				} 
				else
				{ 
					$ratio = (intval(($width / $newWidth) * 100)) / 100; 
					$width = (intval(($width / $ratio) * 100)) / 100; 
					$height = (intval(($height / $ratio) * 100)) / 100; 
				} 
		$destimg=ImageCreateTrueColor($width,$height); 
		switch ($file_type) 
		{ 
			case 1: 
				$srcimg = imagecreatefromgif($src); 
				if (function_exists(ImageGIF)) 
					$imgType = "gif"; 
				else
					$imgType = "jpeg"; 
			break; 
			case 2: 
				$srcimg = imagecreatefromjpeg($src); 
				$imgType = "jpeg";   
			break; 
			case 3: 
				$srcimg = imagecreatefrompng($src); 
				$imgType = "png"; 
			break; 
			default: 
			break; 
		} 
		ImageCopyResized($destimg,$srcimg,0,0,0,0,$width,$height,ImageSX($srcimg),ImageSY($srcimg)); 
		if ( !$dest ) { header ("Content-type: image/$imgType"); } 
		switch ($file_type) 
		{ 
			case 1: 
				if (function_exists(ImageGIF)) 
					if ( $dest) { imagegif ($destimg, $dest); } else { imagegif($destimg); } 
				else 
					if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); } 
			break; 
			case 2: 
				if ( $dest) { imagejpeg ($destimg, $dest); } else { imagejpeg($destimg); } 
			break; 
			case 3: 
				if ( $dest) { imagepng ($destimg, $dest); } else { imagepng($destimg); } 
			break; 
			default: 
			break; 
		} 
		imagedestroy ($srcimg); 
		imagedestroy ($destimg); 
	} 

?>
Random Solutions  
 
programming4us programming4us