dutchboy Posted February 18, 2008 Share Posted February 18, 2008 Hope someone can help. I have an upload script which uploads images and creates a thumbnail and puts them into seperate thumbnail/fullimage folders on the server and adds the file name to my sql database. I have built a simple CMS which enables me to edit individual rows on a database and delete rows using this script <?php include("config.php"); $id = $_GET['id']; $result = mysql_query("DELETE FROM markers WHERE id='$id' ",$connect); header( 'Location:genxml.php' ) ; ?> The id is obtained by passing the variable through a hyper link on my "database manager" page. This works well and deletes the particular entry from the database but does'nt deal with the images stored on the server. I was hoping to pass more variables through my hyperlink so that i can use the unlink function in the above script but dont know if this would work. Below is an attempt which might clear things up a little. <?php include("config.php"); $imagedir = "dbimages/"; $thumbnaildir = "dbimages/thimages/"; $id = $_GET['id']; $pic1del = "$imagedir" . $_GET['photo1']; $thumb1del = "$thumbnaildir" . $_GET['photo1']; unlink($pic1del); unlink($thumb1del); $result = mysql_query("DELETE FROM markers WHERE id='$id' ",$connect); header( 'Location:genxml.php' ) ; ?> from link <a href=delete.php?id=$id&photo1=$photo1>Delete</a> so as you can see i want to pass my image names to the delete page, add the file path and delete the images as well as the database row...... but i dont know if im going about it the correct way as im a noob to php. (thumbnail is named the same as the original image which is why i call 'photo1' twice, just saved in the different folders!) hope someone can help, thanks in advance. Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 18, 2008 Share Posted February 18, 2008 Yes you are right thats the way you can delete images from server Quote Link to comment Share on other sites More sharing options...
Chris92 Posted February 18, 2008 Share Posted February 18, 2008 I understand what you want to do, maybe it would be easier just to store all the info in the database and just get the image id to be deleted from the query string: <?php include("config.php"); $query = mysql_query("SELECT * FROM `markers` WHERE `id`='{$_GET['id']}' ",$connect); $array = mysql_fetch_assoc($query); if( unlink("dbimages/{$array['image']}") ) { echo "Successfully deleted dbimages/{$array['image']}"; } else { die ("Could not delete dbimages/{$array['image']}"); } if( unlink("dbimages/thimages/{$_GET['photo1']}") ) { echo "Successfully deleted dbimages/thimages/{$array['image']}"; } else { die ("Could not delete dbimages/thimages/{$array['image']}"); } mysql_query("DELETE FROM `markers` WHERE `id`='{$_GET['id']}' ",$connect); header('Location:genxml.php'); ?> Quote Link to comment Share on other sites More sharing options...
dutchboy Posted February 18, 2008 Author Share Posted February 18, 2008 Wow quick response thanks! Please forgive my stupidity could you ellaborate a little more on "maybe it would be easier just to store all the info in the database and just get the image id to be deleted from the query string" do you mean actually upload the pictures into the database? Quote Link to comment Share on other sites More sharing options...
dutchboy Posted February 18, 2008 Author Share Posted February 18, 2008 ok scratch the above message the script above works like a charm!! thank you so much Chris92 ive been struggling with this one! really can't thank you enough! Quote Link to comment 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.