Mini Shell
<?php include('header.php') ?>
<?php
$banner = new Banner();
$flash = array();
// UPDATE
if(isset($_POST['action']) && $_POST['action'] == 'update'):
unset($_POST['action']);
$file = $_FILES['image'];
$banner_edit = $banner->find($_GET['id']);
$image_edit = false;
if(strlen($_POST['title']) > 1 && strlen($_POST['link']) >= 1):
if($file['size'] > 1):
list($image_width, $image_height) = getimagesize($file['tmp_name']);
if($image_width == 1200 && $image_height == 500):
$file_name = explode('.', $file['name']);
$file_ext = end($file_name);
// new name
$file_name = md5(time()) .'.'. $file_ext;
$image_edit = true;
else:
$file_name = $banner_edit->image;
endif;
else:
$file_name = $banner_edit->image;
endif;
$_POST['image'] = $file_name;
if($banner->update($_GET['id'], $_POST)):
if($image_edit):
move_uploaded_file($file['tmp_name'], DIR_IMG .'banners/'. $file_name);
endif;
$flash = Helper::flash('success');
else:
$flash = Helper::flash('error');
endif;
else:
$flash = Helper::flash('error');
endif;
endif;
$banner = $banner->find($_GET['id']);
?>
<div id="page">
<div class="row">
<div class="col lg-12">
<h2>Banners / editar</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">×</span></button>
<?= $flash['message'] ?>
</div>
</div>
<?php endif ?>
<div class="col-lg-12">
<a href="banners.php" class="btn btn-primary">Voltar</a>
<hr>
<small>* todos os campos são obrigatórios</small><br>
<small>* Tamanho permitido de imagem é 1200x500 px</small><br>
<small>* imagem apenas caso queira atualizá-la</small>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Título:</label>
<input type="text" name="title" class="form-control" value="<?= $banner->title ?>">
</div>
<div class="form-group">
<label for="link">Link:</label>
<input type="text" name="link" class="form-control" value="<?= $banner->link ?>">
</div>
<div class="form-group">
<label for="image">Imagem: <small>(dimensões 1200x500 px)</small></label>
<input type="file" name="image" class="form-control">
</div>
<div class="form-group">
<input type="hidden" name="action" value="update">
<button type="submit" class="btn btn-primary">Atualizar</button>
</div>
</form>
</div>
<div class="col-lg-6">
<img src="<?= URL_IMG .'banners/'. $banner->image ?>" class="img-thumbnail img-responsive" alt="">
</div>
</div>
</div>
<?php include('footer.php') ?>
Zerion Mini Shell 1.0