admin2gd1 Posted September 3, 2008 Share Posted September 3, 2008 I need some help with 2 functions here. I had trouble getting any of it working before but I have manage to make several corrections but I still need help with 2 things. 1. I can't delete the photo file from database until my check is corrected as it will not go passed it to continue the code. 2. If I don't have my check code inserted I can delete the file perfectly well from the database but can not get it to delete the file from the directory the photo was uploaded too. Here is my latest code. <?php if($_GET['mode'] == "delete_photo"){ if (isset($_GET['photo'])) { $photo = (int) $_GET['photo']; } else { $photo = false; } if (($photo === false) || ($photo < 1) || ($photo > 12)) { $msg = "Error: photo number not specified or out of range!"; } ///// Checks if any Photo has been Removed Already or not been Uploaded Before ///// $check = "SELECT photo".$_GET['photo']." FROM ".TBL_PROPERTIES." WHERE property_id='".$_GET['id']."' AND username='$session->username' "; if(@mysql_query($check)){ if ($check == $empty){ $msg3 = "Photo ".$_GET['photo']." has either already been removed or no photo was uploaded before."; }else{ $msg3 = "ERROR: There seems to be a problem, please contact administrators for help at " . ADMIN_EMAIL . " !"; } }else{ ///// Remove Photos from Directory and DB ///// $get_file = mysql_query("SELECT photo".$_GET['photo']." FROM ".TBL_PROPERTIES." WHERE property_id='".$_GET['id']."' AND username='$session->username' AND name='$name' ") or die ( mysql_error() ); list($del_path) = mysql_fetch_row($get_file); @unlink("$SITEurl/photos/properties/{$session->username}/$name/$del_path"); $deletefile = mysql_query("DELETE photo".$_GET['photo']." FROM ".TBL_PROPERTIES." WHERE property_id='".$_GET['id']."' "); if(@mysql_query($deletefile)){ $msg2 = "Photo <b>".$_GET['photo']."</b> has been deleted!"; }else{ $msg2 = "ERROR: Theres a problem deleting <b>photo ".$_GET['photo']."</b> from your property photo directory, please contact administrators for help at " . ADMIN_EMAIL . " !"; } $sql = mysql_query("DELETE FROM ".TBL_PROPERTIES." WHERE property_id='".$_GET['id']."' AND photo".$_GET['photo']."='$photo' ") or die ( mysql_error() ); $lastedit = date("Y:m:d H:i:s"); $sqlUPDATE = "UPDATE ".TBL_PROPERTIES." SET photo".$_GET['photo']."='', last_edit='$lastedit' WHERE property_id='".$_GET['id']."' "; if(@mysql_query($sqlUPDATE)){ $msg = "You have removed <b>photo ".$_GET['photo']."</b> from your property!"; }else{ $msg = "ERROR: Theres a problem removing photo ".$_GET['photo'].", please contact administrators for help at " . ADMIN_EMAIL . " !"; } } } ?> If I can get some help to fix those 2 problems that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/122541-removing-photo-and-deleting-file-from-directory/ 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.