Jump to content

Unlink from a choice


richard_PHP

Recommended Posts

Hello,

 

I'm wanting to create a script which deletes an image from both a database and off the directory. I understand that the code needed to remove from the directory is UNLINK, I'm having trouble finding how to put it into my code.

 

As follows:

 

<?php
				$conn = mysql_pconnect("#####", "###", "####");
				mysql_select_db("###", $conn);
				$choice = $_POST[choice];
				mysql_query("DELETE FROM ## WHERE id='$choice'");
				echo "<p>Image has been deleted.</p>";
				echo "<p>Click <a href='adminphotos.php'>here</a> to delete another.</p>";
			?>

 

So our user has selected with a radio button which image they would like to delete and this page processes that. At the moment the above code removes from the database.

 

Thanks in advance!

Link to comment
Share on other sites

In the previous page I have pulled the information from the database (id and imgurl) for use in this process. The above code uses the id number as choice and removes where they match. Could I just have the unlink as follows:

 

$imgurl = $_POST[imgurl];

unlink($url);

 

Cheers.

Link to comment
Share on other sites

In the previous page I have pulled the information from the database (id and imgurl) for use in this process. The above code uses the id number as choice and removes where they match. Could I just have the unlink as follows:

 

$imgurl = $_POST[imgurl];

unlink($url);

 

Cheers.

 

yes mate as long as the $_POST['imgurl is the full path to the file if not then you must put

 

unlink("/path/to/files/".$imgurl);

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.