8 Replies - 258 Views - Last Post: 16 March 2014 - 01:31 PM Rate Topic: -----

#1 jtgmagic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 14

unlink() function not deleting files

Posted 14 March 2014 - 10:31 PM

I have a <a>, on click delete a product from database that is on server, I want to delete the product
and the same time delete the image of that product. I using unlink() my code delete the product but don't
delete the image and I don't no why someone can tell me what is missing ?

if((isset($_GET["remove"])) && ($_GET["remove"] != "")){

    $idproduct = $_GET["remove"];

    $sql ="DELETE FROM product WHERE idproduct = '".$idproduct."'";
    if(mysqli_query($connect, $sql) or die ("Erro")){

    //the part that don't work 
    $file = $frontpage_url."/images/".$_FILES["imagem"]["name"]; unlink($file);

    echo "success";

    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: unlink() function not deleting files

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 620
  • View blog
  • Posts: 2,780
  • Joined: 03-December 12

Re: unlink() function not deleting files

Posted 14 March 2014 - 11:17 PM

If you echo $file does it show the correct path and file name? Does the script have delete permissions?

This post has been edited by astonecipher: 14 March 2014 - 11:19 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3359
  • View blog
  • Posts: 11,373
  • Joined: 12-December 12

Re: unlink() function not deleting files

Posted 15 March 2014 - 04:52 AM

Does it echo "success"? If not then it might be the if statement that is a problem.
Was This Post Helpful? 0
  • +
  • -

#4 jtgmagic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 14

Re: unlink() function not deleting files

Posted 15 March 2014 - 11:34 AM

yes have delete permissions, the product are deleting it no problem it inly the image don't delete

this is the direction of the folder in data base $frontpage_url."/images/"

View Postandrewsw, on 15 March 2014 - 04:52 AM, said:

Does it echo "success"? If not then it might be the if statement that is a problem.



//the part that don't work
$file = $frontpage_url."/images/".$_FILES["imagem"]["name"]; unlink($file);
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3359
  • View blog
  • Posts: 11,373
  • Joined: 12-December 12

Re: unlink() function not deleting files

Posted 15 March 2014 - 11:38 AM

You seem to have skipped past the two questions asked:

Does it print out "success"?
Does echoing $file produce a valid path and filename?
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 620
  • View blog
  • Posts: 2,780
  • Joined: 03-December 12

Re: unlink() function not deleting files

Posted 15 March 2014 - 11:47 AM

So instead of using

.$_FILES["imagem"]["name"]; 


You are concerned with the name only not the file itself. Is the file name and the productid the same?
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: unlink() function not deleting files

Posted 15 March 2014 - 12:15 PM

FYI, this is cross-posted
Was This Post Helpful? 0
  • +
  • -

#8 jtgmagic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-March 14

Re: unlink() function not deleting files

Posted 16 March 2014 - 01:13 PM

View Postandrewsw, on 15 March 2014 - 11:38 AM, said:

You seem to have skipped past the two questions asked:

Does it print out "success"?
Does echoing $file produce a valid path and filename?



Does it print out "success"?
everthing work fine and print success ONLY the unlink() is not working
print success but DON'T delete a image from the folder.

Does echoing $file produce a valid path and filename?
and no is not valid

View Postastonecipher, on 15 March 2014 - 11:47 AM, said:

So instead of using

.$_FILES["imagem"]["name"]; 


You are concerned with the name only not the file itself. Is the file name and the productid the same?


no, have diferent names product and image
the images have the original name

$frontpage_url."/images/" (where Iam saving the images)

I want to delete the image associate to the row of that product
Was This Post Helpful? 0
  • +
  • -

#9 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 620
  • View blog
  • Posts: 2,780
  • Joined: 03-December 12

Re: unlink() function not deleting files

Posted 16 March 2014 - 01:31 PM

Before you delete the image select the name of the file to be deleted. Then place the variable holding the name in the $file variable in place of the file array you are using.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1