1
I have the following code below:
//carrega a imagem anterior
$img = $db->prepare("select ipco_descr_multimidia,ipco_arquivo from ipco_multimida where ipco_id_questao_fk = :id ");
$img->bindParam(':id',$id);
//executa a query
$img->execute();
//recupera os valores da tabela
$resultado = $img->fetchAll();
$caminho = $resultado['ipco_arquivo'];
$nome = $resultado['ipco_descr_multimidia'];
//apagar o arquivo antigo da pasta
if(file_exists($caminho.$nome)) {
@unlink($caminho.$nome);
//exit;
}
Multimedia table:
ipco_descr_multimidia | ipco_arquivo
1413297340.jpg | ./img/upload/
When I run the code, it does not erase the image inside the img/upload folder.
Start by removing the
@
which removes the error inunlink
and maybe you get to have more clues than is wrong...– gmsantos
The problem is more related to removing the file from the database. Check the folder permissions. Put the operating system you are using.
– rray
Solved, missing add position of $ipco_descr_multimidia array = $result[0]['ipco_descr_multimidia'];
– hulckb
Is he finding the file? That is, the instruction
file_exists($caminho.$nome)
is returningTRUE
? It can also be a location problem. As your folder structure is, the file you are running is in the same location as the folderimg
?– KaduAmaral
@hulckb put as answer the procedure you performed to solve the problem.
– rray
CARING The function of PHP
file_exists()
returnTRUE
if the path ends in a directory, that is, if the variable$nome
is empty, the current code enters the sameIF
. Use the functionis_file()
is the safest way to check whether the file exists.– Zuul