I'm trying to migrate MYSQL to the PDO, and I came across a problem with Unlink.
With the code below I can do the UPDATE in the BD Banner table, and also store the new file in the destination folder (img_banner), but not replacing the previous file in the destination folder.
<?php
if(isset($_POST['banner'])){
$codigo = $_GET['codigo'];
$imagem = $_POST['imagem'];
$sqlUpdate = 'UPDATE banner SET imagem = ? WHERE codigo = ?';
$dados = array($imagem, $codigo);
$pasta = '../img_banner/';
if (isset($_POST['banner'])){
$check = @$_POST['apagar'];
foreach($check as $imagem){
$delcheck = $sqlUpdate = 'UPDATE banner SET imagem = ? WHERE codigo = ?' or die (mysql_error());
unlink($pasta.'/'.$imagem);
if ($delcheck >= '1'){
echo 'Imagem deletada com sucesso!';
}else{
echo 'Erro ao deletar imagem, tente novamente!';
}}}}
?>
<?php include 'upload_banner.php'; ?>
<form action="" method="POST" enctype="multipart/form-data">
<input size="1" type="hidden" name="codigo" value="<?php echo $codigo?>" readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $imagem ?>" checked readonly>
<label>Selecione uma nova imagem:</label><br />
<input type="file" name="imagem[]" accept="image/*" ><br />
<input type="submit" name="banner" value="Atualizar">
</form>
With this code you are introducing the following errors below:
Error 01:
Notice: Undefined index: image in C: \ wamp \ www \ Commerce \ admin \ edit_banner__initial-upd.php on line 41
Error 02:
Notice: unlink (../ img_banner //); Permission denied in C: \ wamp \ www \ Commerce \ admin \ edit_banner_initial-upd.php on line 53
Any help will be very welcome.;)