Jump to content

Unable to delete images from the directory


booxvid

Recommended Posts

In this program, i would be deleting all images in an album if ever I would choose to delete an album where there's photos in it.

 

<?php require_once("../../includes/initialize.php"); ?>
<?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?>
<?php
$photo = Photograph::count_all_photosin_album($_GET['album_id']);
//$album = Album::find_by_id($_GET['album_id']);

if(empty($_GET['album_id'])){
	$session->message("No album ID was provided.");
	redirect_to('list_album.php');
}
else{

	if($photo>0){

		$sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'";
		$result = $database->query($sql);

		$sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'";
		$result2 = $database->query($sql2);

		$sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'";
		$result3 = $database->query($sql3);

		while($row=mysql_fetch_array($result3)){
			$photo_id = Photograph::find_by_id($_GET['album_id']);
			if($photo_id && $photo_id->destroy()){
				echo "SUCCESS!";
			}


		}
	}
	else{


	}
}

  
?>
<?php if(isset($database)) { $database->close_connection(); } ?>

 

I already delete the images from my photo table in mysql and also the album record

in my album table in mysql but I was unable to delete the images from that album in my directory \:

Link to comment
Share on other sites

I already transfer the deleting of photos in the database right after deleting the photos in the directory

 

<?php require_once("../../includes/initialize.php"); ?>
<?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?>
<?php
$photo = Photograph::count_all_photosin_album($_GET['album_id']);


if(empty($_GET['album_id'])){
	$session->message("No album ID was provided.");
	redirect_to('list_album.php');
}
else{

	if($photo>0){
		echo "DELETE";
		$sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'";
		$result = $database->query($sql);



		$sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'";
		$result3 = $database->query($sql3);

		while($row=mysql_fetch_array($result3)){
			$target_path =SITE_ROOT.DS."public".DS. "images/".$row['filename'];
			unlink($target_path);				
			echo "SUCCESS!";				
			$sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'";
			$result2 = $database->query($sql2);

		}
	}
	else{

	}
}

?>
<?php if(isset($database)) { $database->close_connection(); } ?>

 

but still, the same problem \:

Link to comment
Share on other sites

Try this:

$sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'";
echo $sql3;
$result3 = $database->query($sql3) or die(mysql_error());
if(mysql_num_rows($result3)==0){
echo 'no photo found with album_id: '.$_GET['album_id'];
}

Why is there more than one photo with $_GET['album_id']?

Link to comment
Share on other sites

I'm having an album_id property in my photo table which is connected to my album table that

has a album_id property as well (:

 

Thanks for the help!

Ah, right, think I confused it with being the photo's ID. Anyways, did you get some useful information when you tried what I posted? I believe it would be interesting for us if you posted the result, at least if you still need any help!

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.