<?php
/*Servo Recipe*/
/*Recipe Name: Accept File Upload*/
/*Recipe Description: This recipe accepts a file upload, and saves the file into your server's temporary directory using the file extension of the uploaded file. Prints the filename to the browser so that you can find the file on disk.*/
/*Servo Recipe*/
?>


<?php
/*s3rvo_functiondef_ZMEGOBRCCA*/
/*Title: Get File Upload Extension*/
/*Object: escapers_file_upload_extension.json*/
/*Description: Returns the file extension for a given file upload field. */
/*Tint: #CE2438*/
function aer_file_upload_extension($formname) {
	$name = $_FILES[$formname]["name"];
	$ext = end((explode(".", $name))); 
	return $ext;
}
/*s3rvo_functiondef_ZMEGOBRCCA*/



/*s3rvo_functioncall_PAICWUOMZG*/
/*Title: Get File Upload Extension*/
/*Object: escapers_file_upload_extension.json*/
/*Description: Returns the file extension for a given file upload field.*/
/*Tint: #CE2438*/
/*s3rvo_return_value*/$fileext= /*s3rvo_return_value*/servo_file_upload_extension(
/*s3rvo_param_$formname*/"filetoupload"/*s3rvo_param_$formname*/
);
/*s3rvo_functioncall_PAICWUOMZG*/




/*s3rvo_functiondef_SQISLHOGTE*/
/*Title: Accept File Upload*/
/*Object: escapers_accept_file_upload.json*/
/*Description: Accepts a file upload from a web page*/
/*Tint: #CE2438*/
function aer_accept_file_upload($formname,$maximumsize,$filepath) {

	if($_FILES[$formname]['name'])
	{
		if(!$_FILES[$formname]['error'])
		{
			if($_FILES[$formname]['size'] > ($maximumsize))
			{
				echo "File is too big.";
				return false;
			}
			
			return move_uploaded_file($_FILES[$formname]['tmp_name'], $filepath);	
			
		}
		else
		{
			echo $_FILES[$formname]['error'];
			return false;
		}
	}
	
	return false;
}
/*s3rvo_functiondef_SQISLHOGTE*/



/*s3rvo_functiondef_WCZTTDWJLE*/
/*Title: Create unique filename in folder with advanced options*/
/*Object: escapers_create_unique_filename_advanced.json*/
/*Description: Creates a unique filename for the given folder, along with some options*/
/*Tint: #995577*/
function aer_create_unique_filename_in_folder($dir,$prefix,$extension) {

	$alpha_numeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	$filename = $dir . DIRECTORY_SEPARATOR . $prefix.substr(str_shuffle($alpha_numeric), 0, 8).".".$extension;
	while (file_exists($filename)) {
		$filename = $dir . DIRECTORY_SEPARATOR . $prefix.substr(str_shuffle($alpha_numeric), 0, 8)."."+$extension;
	}
	return $filename;

}
/*s3rvo_functiondef_WCZTTDWJLE*/




/*s3rvo_functioncall_BEWGCBSVXT*/
/*Title: Create unique filename in folder with advanced options*/
/*Object: escapers_create_unique_filename_advanced.json*/
/*Description: Creates a unique filename for the given folder, along with some options*/
/*Tint: #995577*/
/*s3rvo_return_value*/$filename = /*s3rvo_return_value*/servo_create_unique_filename_in_folder(
/*s3rvo_param_$dir*/sys_get_temp_dir()/*s3rvo_param_$dir*/,
/*s3rvo_param_$prefix*/"SERVOUPLOAD"/*s3rvo_param_$prefix*/,
/*s3rvo_param_$extension*/$fileext/*s3rvo_param_$extension*/
);
/*s3rvo_functioncall_BEWGCBSVXT*/





/*s3rvo_functioncall_KGIBTCXFUC*/
/*Title: Accept File Upload*/
/*Object: escapers_accept_file_upload.json*/
/*Description: Accepts a file upload from a web page*/
/*Tint: #CE2438*/
/*s3rvo_return_value*/$result = /*s3rvo_return_value*/servo_accept_file_upload(
/*s3rvo_param_$formname*/"filetoupload"/*s3rvo_param_$formname*/,
/*s3rvo_param_$maximumsize*/10000000/*s3rvo_param_$maximumsize*/,
/*s3rvo_param_$filepath*/$filename/*s3rvo_param_$filepath*/
);
/*s3rvo_functioncall_KGIBTCXFUC*/







/*s3rvo_usercode_VJNTLJOHYH*/
/*Title: Print filename...*/
/*Description: Probably want to remove this for a live page...*/
/*Tint: #772233*/
//code
echo $filename;
//code

/*s3rvo_usercode_VJNTLJOHYH*/







?>