Jump to content

problem deleting a file with unlink()


phpkode

Recommended Posts

Dear forum

 

I'm new to this forum and since I'm doing more and more php development, you'll probably going to see me more. 

 

For now I got this problem and I hope you guys can help me out =(.

 

I'm building an administartion panel for a website. On this panel the administrator can upload pictures for a gallery. This part works, so normally permissions shouldn't be a problem.

The file names are stored in my mysql database for example "pic2.jpg", "pic2.jpg", ...

 

Now I got this form to delete pictures from a specific gallery. It deletes from the database but it just wont delete the files. I'm using a local xampp server.

 

I got the following code:

 

Code:

$merk = $_POST["MerkLeegMaken"];

      $sql = "SELECT * FROM catalogus WHERE merkId=" . $merk;

      $resultSet = mysql_query($sql);

      while ( $row = mysql_fetch_array($query) )

        {

            $url = "../uploads/" . $row["foto"]; // this url is f.e. "../uploads/picture1.jpg", and I'm currently in "/administrationPanel/form.php

            fclose($url);

            unlink($url);

        }

           

     

      $sql = "DELETE FROM catalogus WHERE merkId=" . $merk;

      mysql_query($sql);

      $message = "<p class='success'>Het huidig merk is succesvol leeggemaakt.</p>";

 

 

(I got in my root dir the directory /uploads and the directory /administartionPanel, so ../uploads should be correct right?"

 

 

I also tried to delete with "c:/xampp/xampp/htdocs/uploads/pic1.jpg" but that didn't work either. But shouldn't "../uploads/pic1.jpg" work anyway, since I use that same url as the source of an Image below the form.

 

All my different url attempts didn't work. I kept finding the files in my windows explorer =(

 

Hope someone can help.

 

 

www.phpkode.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.