Jump to content

Recommended Posts

Basically i have a table show the contents of database (id, name, image type, image size). This is it,

http://dvplus.webuda.com/testing/delete-image.php

The image on the last column i want it have a href on that image that will delete the file directory that relevant on the table row. I tried to user <a href="<? unlink="" ?>img scr</a>.....,

 

any one got any idears???

Link to comment
https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/
Share on other sites

PHP is executed server-side. You can't put PHP code into a link expecting it to be executed when the user clicks the link. The link needs to point to a php on the server that will get called when the user clicks a link.

 

So, you could create a page (say deleterecord.php) then for each link have the href pointed to that page and add an additional parameter to include the record id. So the link would look something like this

<a href="deleterecord.php?id=123">Delete this record</a>

 

Then you need to create that page to take the id passed on the query string and perform the delete operation.

Yes, and on the deleterecord.php page you should have a confirm delete form that submits the delete operation using POST not GET.  You could do this on the original page instead if you wanted.  Don't create/modify or delete with GET.

Right i have made a new php file to delete the image but it keeps coming up 'Warning: unlink() [function.unlink]: http does not allow unlinking in /home/a2820511/public_html/testing/image-deleted.php on line 9'

This is how i have done it....

 

Table file

  <?php
while($rows=mysql_fetch_array($result)){ // Start looping table row 
?>
  <tr>
    <td class="some-shit"><? echo $rows['id']; ?></td>
    <td class="some-shit"><a href="<? echo $rows['name']; ?>"><? echo $rows['name']; ?></a><br /></td>
    <td align="center" ><? echo $rows['type']; ?></td>
    <td align="center" ><? echo $rows['size']; ?></td>
    <td align="center" ><a href="image-deleted.php?id=<? echo $rows['name'] ?>"><img src="LAS/images/icons/admin/hds/delete.jpg" alt="" width="19" height="19" border="0" /></a></td>
  </tr>
  <?php
// Exit looping and close connection 
}
mysql_close();
?>

 

Delete image file

<?php 
$imageDir=$_GET["id"];
unlink($imageDir);
?>
<script language="text/javascript">
window.location ="delete-image.php";
</script>

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.