Skip to content

Instantly share code, notes, and snippets.

@joaocarvalhowd
Last active August 29, 2015 14:02
Show Gist options
  • Save joaocarvalhowd/70376847c260a1c0f8ae to your computer and use it in GitHub Desktop.
Save joaocarvalhowd/70376847c260a1c0f8ae to your computer and use it in GitHub Desktop.
Deletar imagem Pasta e BD
<?php
include "config.php";
$id = isset($_GET['id']) ? $_GET['id'] : null;
$busca = mysql_query("SELECT * FROM `banner-top` WHERE id = {$id}")
or die ("Erro ao realizar buscas");
if ($row = mysql_fetch_array ($busca))
{
$diretorio = '/'; // Depois você coloca o seu diretorio correto. Este diretório poderia estar dentro do arquivo conexao.php (para ficar dinamico)
$arquivo = $diretorio.$row['banner_a']; // diretorio + o nome do arquivo/foto
if (file_exists($arquivo)) {
print "O arquivo $arquivo existe";
} else {
print "O arquivo $arquivo não existe";
}
if (unlink($row['banner_a']));
}
// exclui o arquivo do servidor
// na sequencia exlui o registro
$sql = mysql_query("DELETE FROM `banner-top` WHERE id = {$id}");
if($sql){
header("location:administrar-banner-top.php");
}else{
print "Não foi possivel deletar o redado. Tente mais tarde!";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment