Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Created April 14, 2014 15:49
Show Gist options
  • Select an option

  • Save leocavalcante/10660004 to your computer and use it in GitHub Desktop.

Select an option

Save leocavalcante/10660004 to your computer and use it in GitHub Desktop.
<?php
$imagem = $_FILES['imagem'];
$logradouro = $_REQUEST['logradouro'];
$preco = $_REQUEST['preco'];
$modo = $_REQUEST['modo'];
$excluir = $_REQUEST['excluir'];
if($modo == "cadastro"){
$stmt = $db->prepare('insert into imoveis (logradouro, preco) values(?, ?)');
$stmt->bindValue(1, $logradouro);
$stmt->bindValue(2, $preco);
$stmt->execute();
if (!empty($imagem["name"])) {
// Pega extensão da imagem
preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $imagem["name"], $ext);
// Gera um nome único para a imagem
$nome_imagem = md5(uniqid(time())) . "." . $ext[1];
// Caminho de onde ficará a imagem
$caminho_imagem = "uploads/" . $nome_imagem;
move_uploaded_file($imagem["tmp_name"], $caminho_imagem);
}
}
if(!empty($excluir)){
$stmt = $db->prepare('delete from imoveis where id = ?');
$stmt->bindValue(1, $excluir);
$stmt->execute();
$mensagem = "Cadastro excluido";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment