son.of.the.morning Posted September 8, 2010 Share Posted September 8, 2010 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??? Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/ Share on other sites More sharing options...
Psycho Posted September 8, 2010 Share Posted September 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108805 Share on other sites More sharing options...
son.of.the.morning Posted September 8, 2010 Author Share Posted September 8, 2010 any idear on how the code should be in the delete page? Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108810 Share on other sites More sharing options...
AbraCadaver Posted September 8, 2010 Share Posted September 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108811 Share on other sites More sharing options...
son.of.the.morning Posted September 8, 2010 Author Share Posted September 8, 2010 I would rather do it on a whole new page becuase i want to have a confirm delete code plus i want to remove the record from the database to. I havnt got a clue were to start though Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108818 Share on other sites More sharing options...
son.of.the.morning Posted September 8, 2010 Author Share Posted September 8, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108832 Share on other sites More sharing options...
son.of.the.morning Posted September 8, 2010 Author Share Posted September 8, 2010 anyone??? Quote Link to comment https://forums.phpfreaks.com/topic/212886-using-unlink-to-delete-a-file/#findComment-1108842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.