Jump to content

Removing photo and deleting file from directory


admin2gd1

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.