wrathican Posted July 21, 2008 Share Posted July 21, 2008 hey im making an image gallery and ive hit a technical hitch with the 'delete album' section i have my code so that the user selects an album to delte and the Id is sent to my processing script. the script then does the following this order. 1 - sees if there are any images in the images table that belong to that album -if not it deletes the album from the table if so: 2 - it gets the names of the files that belong to that album from the db 3 - it deletes (using unlink()) the file from the server but when i process the script every image from all the albums gets deleted. here is my script: <?php $alId = $_POST['album']; $imQuery = "SELECT * FROM won_picture WHERE pic_albumid='".$alId."'"; $imResult = query($imQuery); $imNumRows = numRows($imResult); if($imNumRows == 0) { //no images connected to the album. delete album $alQuery = "DELETE FROM won_album WHERE album_id='".$alId."'"; $alResult = query($alQuery); if($alResult) { //album was deleted $_SESSION['errorstate'] = 1; $errorarray[] = "Thank you. The album you selected has been deleted."; $_SESSION['errormessage'] = $errorarray; header('location: ../admin/index.php'); }else{ //album was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, the album has not been deleted. Please try again."; $_SESSION['errormessage'] = $errorarray; header('location: ../admin/galleryadmin.php?func=delalbum'); } }else{ //images are connected to album while($row = mysql_fetch_array($imResult)) { $id = $row['pic_id']; $thumb = $row['pic_thumb']; $image = $row['pic_image']; $title = $row['pic_title']; $thDel = unlink('../images/thumbs/'.$thumb); $imDel = unlink('../'.$image); if($thDel) { //thumb was deleted if($imDel) { //image was deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The image titled ".$title." has been deleted."; }else{ //image was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The image titled ".$title." has not been deleted, but the thumbnail was."; } }else{ //thumb was not deleted $_SESSION['errorstate'] = 1; $errorarray[] = "The thumbnail image titled ".$title." has not been deleted and neither has the full size image.."; } } $_SESSION['errormessage'] = $errorarray; header('location: ../admin/galleryadmin.php?func=delalbum'); } ?> Link to comment https://forums.phpfreaks.com/topic/115835-solved-deleting-files-with-unlink/ Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 try echoing pic_albumid in your while loop..the problem may be related to data.. Link to comment https://forums.phpfreaks.com/topic/115835-solved-deleting-files-with-unlink/#findComment-595473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.