Mini Shell

Direktori : /home/emypro/www/admin/
Upload File :
Current File : /home/emypro/www/admin/attachments.php

<?php include('header.php') ?>
<?php
$attachment = new Attachment();

$flash = array();
// CREATE
if(isset($_POST['action']) && $_POST['action'] == 'create'):
	unset($_POST['action']);
	
	$file = $_FILES['image'];

	if($file['size'] > 1):

		$file_name = explode('.', $file['name']);
		$file_ext  = end($file_name);

		// new name
		$file_name = md5(time()) .'.'. $file_ext;

		$_POST['image'] = $file_name;
		
		if($attachment->create($_POST)):
			move_uploaded_file($file['tmp_name'], DIR_IMG .'attachments/'. $file_name);
			$flash = Helper::flash('success');
		else:
			$flash = Helper::flash('error');
		endif;

	endif;
endif;

// DELETE
if(isset($_GET['action']) && $_GET['action'] == 'delete'):
	if($attachment->delete($_GET['id'])):
		$flash = Helper::flash('success');
	else:
		$flash = Helper::flash('error');
	endif;
endif;

// READ
$attachments = $attachment->condition(array('model' => 'obras', 'reference' => $_GET['id']));
?>
<div id="page">
	<div class="row">
		<div class="col lg-12">
			<h2>Galeria de fotos <span class="label label-default"><?= ucfirst($_GET['model']) ?></span></h2>
		</div>
	</div>
	<div class="row">
		<?php if($flash): ?>
		<div class="col-lg-12">
			<div class="alert alert-<?= $flash['class'] ?> alert-dismissible">
				<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<?= $flash['message'] ?>
			</div>
		</div>
		<?php endif ?>
		<div class="col-lg-12">
			<h4>Novo</h4>
			<form action="" method="post" enctype="multipart/form-data">
				<div class="form-group">
					<label for="image">Imagem: <small>(dimensões 600x450 px)</small></label>
					<input type="file" name="image" class="form-control">
				</div>
				<div class="form-group">
					<input type="hidden" name="model" value="<?= $_GET['model'] ?>">
					<input type="hidden" name="reference" value="<?= $_GET['id'] ?>">
					<input type="hidden" name="action" value="create">
					<button type="submit" class="btn btn-primary">Adicionar</button>
				</div>
			</form>
		</div>
		<div class="col-lg-12">
			<?php foreach($attachments as $attachment): ?>
				<div class="col-xs-6 col-md-3">
					<div class="thumbnail">
						<img src="<?= URL_IMG .'attachments/'. $attachment->image ?>" alt="">
						<div class="caption">
							<a href="attachments.php?model=<?= $_GET['model'] ?>&action=delete&id=<?= $attachment->id ?>" class="btn btn-danger" onclick="return confirm('Deseja realmente deletar?')"><i class="glyphicon glyphicon-trash"></i> Remover</a>
						</div>
					</div>
				</div>
			<?php endforeach ?>
		</div>
	</div>
</div>

<?php include('footer.php') ?>

Zerion Mini Shell 1.0