<?php
if (isset ( $_POST ['save'] )) {
	
	$file_name = SERVER_ROOT . '/uploads/image/' . LOGO;
	$lstid = '1';
	$imagetype = $_FILES ['my_field'] ['type'];
	$query = $db->get_row ( 'setting', array ('id' => '1' ) );
	if (($imagetype [0] == 'image/png' || $imagetype [0] == 'image/jpg' || $imagetype [0] == 'image/jpeg')) {
		if ($query ['c_logo'] != '') {
			$delete1 = $db->update ( 'setting', array ('c_logo' => '' ), array ('id' => $id ) );
			unlink ( $file_name );
		} else {
		}
		
		$cli = (isset ( $argc ) && $argc > 1);
		($cli);
		if ($cli) {
			if (isset ( $argv [1] ))
				$_GET ['file'] = $argv [1];
			print_r ( $_GET ['file'] );
			if (isset ( $argv [2] ))
				$_GET ['dir'] = $argv [2];
			if (isset ( $argv [3] ))
				$_GET ['pics'] = $argv [3];
		}
		
		// set variables
		$dir_dest = (isset ( $_GET ['dir'] ) ? $_GET ['dir'] : 'uploads/image');
		$dir_pics = (isset ( $_GET ['pics'] ) ? $_GET ['pics'] : $dir_dest);
		
		if (! $cli && ! (isset ( $_SERVER ['HTTP_X_FILE_NAME'] ) && isset ( $_SERVER ['CONTENT_LENGTH'] ))) 

		{
			
			$files = array ();
			
			foreach ( $_FILES ['my_field'] as $k => $l ) {
				foreach ( $l as $i => $v ) {
					
					if (! array_key_exists ( $i, $files ))
						$files [$i] = array ();
					
					$files [$i] [$k] = $v;
				}
			}
			
			// now we can loop through $files, and
			// feed each element to the class
			foreach ( $files as $file ) {
				// we instanciate the class for each
				// element of $file
				$name = mt_rand ( 15, 215 ) . "___" . mb_strtolower ( preg_replace ( '/\s+/', '', $file ['name'] ) );
				$file ['name'] = str_replace ( array ('(', ')' ), '', $name );
				$savedname = $file ['name'];
				$handle = new upload ( $file );
				
				// then we check if the file has
				// been uploaded properly
				// in its *temporary* location in
				// the server (often, it is /tmp)
				
				if ($handle->uploaded) {
					
					// now, we start the upload
					// 'process'. That is, to copy
					// the uploaded file
					// from its temporary location
					// to the wanted location
					// It could be something like
					// $handle->Process('/home/www/my_uploads/');
					// we now process the image a
					// second time, with some other
					// settings
					
					$handle->image_resize = true;
					$handle->image_ratio_crop = true;
					$handle->image_y = 40;
					$handle->image_x = 100;
					
					$handle->Process ( $dir_dest );
					
					$settingcheck1 = $db->get_count ( "setting" );
					
					if ($settingcheck1 == 0) {
						$query_insert = $db->insert ( 'setting', array ('c_logo' => $savedname ) );
					} else {
						$query_update = $db->update ( 'setting', array ('c_logo' => $savedname ), array ('id' => '1' ) );
					}
				
				}
			}
		}
	}

}
?>