xcoderx Posted May 8, 2009 Share Posted May 8, 2009 friends i add image to gallery this way $target = "gallery/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("gallery/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "file name already exists <br/>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded."; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; $itemurl = $_POST["itemurl"]; $disc = $_POST["disc"]; $uid = getuid_sid($sid); echo "<p align=\"center\">"; $nopl = mysql_fetch_array(mysql_query("SELECT sex FROM users WHERE id='".$uid."'")); if($nopl[0]=='M') { $usex = "M"; }else if($nopl[0]=='F'){ $usex = "F"; }else{ $usex = "M"; } $res = mysql_query("INSERT INTO gallery SET uid='".$uid."', disc='".$disc."', itemurl='".$target."', sex='".$usex."'"); if($res) { echo "User Photo Added<br/>"; }else{ echo "Database Error<br/>"; } and to delete i use this $gid = $_GET["gid"]; echo "<p align=\"center\">"; $itemowner = mysql_fetch_array(mysql_query("SELECT uid FROM gallery WHERE id='".$gid."'")); if(ismod(getuid_sid($sid))||getuid_sid($sid)==$itemowner[0]) { $res = mysql_query("DELETE FROM gallery WHERE id='".$gid."'"); $res2 = mysql_query("DELETE FROM galcomments WHERE pid='".$gid."'"); $res3 = mysql_query("DELETE FROM rate WHERE pid='".$gid."'"); if($res||res2||res3) { echo "Photo Deleted From Gallery<br/>"; }else{ echo "Database Error!<br/>"; } }else{ echo "You can't delete this Photo"; } echo "<br/><br/>"; echo "</body>"; } now the problem is when i click delete link it does delete the photo from db and do not show in gallery but how do i remove it from the folder with the name of the picture? i have no idea how to add ulink option please help Quote Link to comment Share on other sites More sharing options...
xcoderx Posted May 8, 2009 Author Share Posted May 8, 2009 oh and what im doing is i add the url path of the picture which is being added to the database its not just the name of the picture in particular like this $res = mysql_query("INSERT INTO gallery SET uid='".$uid."', disc='".$disc."', itemurl='".$target."', sex='".$usex."'"); where .$target. prints and inserts the picture url like www.site.com/gallery/image.jpg, im not geting idea now how to pull the only name of the picture to delete Quote Link to comment Share on other sites More sharing options...
briant Posted May 8, 2009 Share Posted May 8, 2009 I believe what you are looking for is an unlink function. You place whatever the URL of the image is inside the unlink function. unlink(IMAGE-URL); Quote Link to comment Share on other sites More sharing options...
xcoderx Posted May 8, 2009 Author Share Posted May 8, 2009 something like $res = mysql_query("DELETE FROM fun_gallery WHERE id='".$gid."'"); $res2 = mysql_query("DELETE FROM fun_galcomments WHERE pid='".$gid."'"); $res3 = mysql_query("DELETE FROM fun_prate WHERE pid='".$gid."'"); unlink("gallery" . $itemurl"); ?? please help me out im not an php expert Quote Link to comment Share on other sites More sharing options...
briant Posted May 8, 2009 Share Posted May 8, 2009 That doesn't look right. Watch your quotes. You need to have them paired. I need to know what your variable values are. If $itemurl equals to what the file name is including the file type (jpg, gif) then that is correct, except the extra quote. Please give me an example of what $itemurl will output. Quote Link to comment Share on other sites More sharing options...
xcoderx Posted May 8, 2009 Author Share Posted May 8, 2009 ok itemurl is where the url of the uploaded photo gets stored and it will output the picture in gallery like using http://site.com/gallery/file.jpg im sure u noticed which uploading the picture i used the $target in adding the url to db in itemurl now i have no idea in deleting it from the folder at the same time. kindly tell me in simple what all codes do i show you? thanks soo much Quote Link to comment Share on other sites More sharing options...
briant Posted May 8, 2009 Share Posted May 8, 2009 Should be right. unlink("gallery".$itemurl); 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.