Unlink: Permission Denied - Trying to get property of non-object

1

Good afternoon guys,

Recently I've been trying to do an image management where I need to use the unlink. Here is the full code for the function:

$query_listaPic = "SELECT * FROM tbl_imagem WHERE tbl_produto_id = '$id'";
$listaPic = mysql_query($query_listaPic, $techConect) or die(mysql_error());
$row_listaPic = mysql_fetch_assoc($listaPic);
$totalRows_listaPic = mysql_num_rows($listaPic);

chmod("../img/produtos", 0755);
while($r = mysql_fetch_object($listaPic))
{
    unlink('../img/produtos/'.$r->nome);
}

$deleteSQL = "DELETE FROM tbl_imagem WHERE tbl_produto_id = '$id'";

$Result1 = mysql_query($deleteSQL, $techConect) or die(mysql_error());


$rand = rand(5,98798967899);

foreach($_FILES['files']['tmp_name'] as $key => $tmp_name)
{
    $filename = $rand.$_FILES['files']['name'][$key];
    $file_tmp = $_FILES['files']['tmp_name'][$key];

    $query = "INSERT INTO tbl_imagem(nome, tbl_produto_id) VALUE ('$filename', '$id')";

    $dir = "../img/produtos/";
    move_uploaded_file($file_tmp, $dir.$filename);

    $Result2 = mysql_query($query, $techConect) or die(mysql_error());

    //echo "<script> alert('Imagens Atualizadas.'); window.location = 'produto-info.php'; </script>";
}

In this section he should select the images that already exist registered in such product, delete them and insert the new ones, but soon in unlink('../img/produtos/'.$r->nome); it returns me an error of:

  

Unlink: Permission Denied - Trying to get property of non-object

In this project I need to insert images into the 'products' url folder of this file (../img/products), and to access them, I insert the name in the tbl_imagl table linked to the tbl_products table. To edit I would delete the records referring to the images and also delete the files, and soon after adding the new files to the folder and the table tbl_imagem. To delete it would just remove the files and remove the records from the DB.

It would look something like this video .

The issue is that I am not able to perform the image editing of the registry, it is not deleting the old images or inserting into the DB (according to the current code described above).

Folder Structure:
Project > img > products > images
Project > admin > administrative pages

SQL:

CREATE TABLE 'tbl_imagem' (  
  'id' int(11) NOT NULL AUTO_INCREMENT,  
  'nome' varchar(100) NOT NULL,  
  'tbl_produto_id' int(11) NOT NULL,  
  PRIMARY KEY ('id'),  
  KEY 'fk_tbl_imagem_tbl_produto1_idx' ('tbl_produto_id')  
);  



CREATE TABLE 'tbl_produto' (  
  'id' int(11) NOT NULL AUTO_INCREMENT,  
  'nome' varchar(50) NOT NULL,  
  'descricao' varchar(255) DEFAULT NULL,  
  'codigotm' varchar(11) NOT NULL,  
  'datacadastro' datetime NOT NULL,  
  'tbl_subcategoria_id' int(11) NOT NULL,  
  PRIMARY KEY ('id'),  
  KEY 'fk_tbl_produto_tbl_subcategoria1_idx' ('tbl_subcategoria_id')  
);  

Thank you all right away!

    
asked by anonymous 22.10.2015 / 17:54

1 answer

0
while($r = $Pic)
{
    unlink('../img/produtos/'.$r->nome);
}

$r gets $Pic , would not it be the same? where is the stop condition?

$Pic = $row_listaPic['nome']; , $r is an array and not an object this is one of the reasons unklink fails.

    
22.10.2015 / 18:05