Location: PHPKode > projects > EZphotopress > ezphotopress-1.0.0/admin/categories/addCategory.php
<h3><?=ADDCATEGORY_TITLE?></h3>
<br>
<?php
if (isset($_POST['action']) && $_POST['action'] == ADDCATEGORY_FORM_SUBMIT) {
	$name = $_POST['name'];
	
	$imageUpload = 0;
	$filename = time();
	$fullPathGallery = "";
	if (@is_uploaded_file($_FILES['image']['tmp_name'])) {
		$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
		$fullPathCategory = $_CONFIG['category_path'].$filename.".".$ext;
		if (@move_uploaded_file($_FILES['image']['tmp_name'], "../".$fullPathCategory)) {
			$imageUpload = 1;
		}
	}
	$query = "insert into ".TABPREFIX."categories(name,path_img,create_date,last_modify,deleted) values(";
	$query .= "'".addslashes($name)."',";
	if ($imageUpload == 1) {
		$query .= "'".$fullPathCategory."',";
	} else {
		$query .= "'',";
	}
	
	$query .= "NOW(),NOW(),0)";
	
	$result = $db->query($query) or die("save categories - ");
	
	if ($result->sizeIDU() != -1) {
		?>
		<p class="ok">
			<?php 
			$msg = '';
			if ($imageUpload == 0) {
				$msg .= ADDCATEGORY_ERROR_UPLOAD;
			}
			?>
			<?=$msg ?>
			<?=ADDCATEGORY_SUCCESS?>
		</p>
		<br>
		<center>
			<a href="home.php?id=cate&action=new" class="back"><?=ADDCATEGORY_LINK?></a>
		</center>
		<?php
	} else {
		?>				
		<p class="ok">
		<?=ADDCATEGORY_ERROR?>
		</p>
		<br>
		<center>
			<a href="home.php?id=cate&action=new" class="back"><?=ADDCATEGORY_LINK?></a>
		</center>
		<?php
		//try to remove the uplodaed files
		try {
			if ($fullPathCategory != "") {
				@unlink("../".$fullPathCategory);
			}
		} catch (Exception $e) {
			echo ADDCATEGORY_EXCEPTION_1;
			echo ADDCATEGORY_EXCEPTION_2;
			echo ADDCATEGORY_EXCEPTION_3. $e->getMessage() . "";
        	echo ADDCATEGORY_EXCEPTION_4. $e->getFile() . "";
        	echo ADDCATEGORY_EXCEPTION_5. $e->getLine();
        	echo ADDCATEGORY_EXCEPTION_6;
		}
	}

} else {
	?>
	<form action="home.php?id=cate&action=new" method="post" name="form_category" id="form_category" enctype="multipart/form-data">
		<input type="hidden" id="idcate" name="idcate" value="-1">
		<fieldset>
			<div>
				<label><?=ADDCATEGORY_FORM_NAME?></label>
				<input type="text" id="idname" name="name"  size="30">
			</div>
			<div>
				<label><?=ADDCATEGORY_FORM_IMAGE?></label>
				<input type="file" name="image">
			</div>
			<div style="text-align: center;">
				<input type="submit" name="action" value="<?=ADDCATEGORY_FORM_SUBMIT?>">
			</div>
		</fieldset>
	</form>
<?php
}
?>

Return current item: EZphotopress