| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 60818 | 2005-08-14 05:37:00 | Php -- Deleting Images | Morgenmuffel (187) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 380858 | 2005-08-14 05:37:00 | Hi all Ok this my 7th rewrite, so hopefully it's coherent-ish I have a database in the following form product table ID Name Price Size Image --- (link to image eg /images/bob.gif) Now if i want to delete a product I can do that easily enough through mysql But This only deletes the link to the image, not the actual image, I want to delete both obviously I have searched Google and yahoo, but all these seem to show is how to selete a record, (or in some case people seem to store images in the dbase) Perhaps i am searching incorrectly, I have seen mention of an "unlink()" function but am unsure wether this actually removes the file or just severs connection to the file for hat session -- (sorry but that is the bit I am hazy on) As always any help would be much appreciated |
Morgenmuffel (187) | ||
| 380859 | 2005-08-14 08:51:00 | Hi all Now if i want to delete a product I can do that easily enough through mysql But This only deletes the link to the image, not the actual image, I want to delete both obviously...Perhaps i am searching incorrectly, I have seen mention of an "unlink()" function but am unsure wether this actually removes the file... nope, thats what your looking for nz.php.net |
sal (67) | ||
| 380860 | 2005-08-14 09:00:00 | Here's a snippet from one of my sites Works well <? require 'config/config.php'; require 'secure.php'; // remove image from listing if($id) { // get filenames from database $link = mysql_connect($dbhost, $dbuser, $dbpass); $query = "SELECT image, thumb FROM $dbimg WHERE id='$id'"; $result = mysql_db_query($dbname, $query, $link); $data = mysql_fetch_array($result); // delete image and thumbnail unlink("thumbs/$data[thumb]"); unlink("images/$data[image]"); // remove entry from database $query = "DELETE FROM $dbimg WHERE id='$id'"; if(mysql_db_query($dbname, $query, $link)) { // update numimages for that listing $query = "UPDATE $dbvin SET numimages=numimages-1 WHERE ccode='$ccode'"; mysql_db_query($dbname, $query, $link); // jump back to summary page mysql_close($link); echo "<script language='JavaScript'> window.location='summary.php?ccode=$ccode'; </script>"; exit(); } @mysql_close($link); } ?> |
bartsdadhomer (80) | ||
| 380861 | 2005-08-14 21:26:00 | Thanks all for clearing that up I'll give it a go later on today :thumbs: |
Morgenmuffel (187) | ||
| 1 | |||||