DeanWhitehouse Posted May 22, 2008 Share Posted May 22, 2008 ok, so this is my code <?php mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); $qu = "SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'"; $res = mysql_query($qu) or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res); $myFile = "../images/".$r['filename']; $fh = fopen($myFile, 'w') or die("can't open file"); fclose($fh); $filename = $r['filename']; unlink($filename); ?> but it is trying to delete the image from admin_area.php, not the folder is ay any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/ Share on other sites More sharing options...
soycharliente Posted May 22, 2008 Share Posted May 22, 2008 I don't understand what you're doing with the DELETE and then SELECT of the same data. Won't it not exist? Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547627 Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 you have to select it before you delete it...also, you build the filename, then overwrite it... <?php $res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res); mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); $myFile = "../images/".$r['filename']; unlink($myFile) or die("can't open file"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547629 Share on other sites More sharing options...
DeanWhitehouse Posted May 22, 2008 Author Share Posted May 22, 2008 that all works fine, it is the unlink that isn;t working Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547630 Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 try this: <?php $res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res); mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); $myFile = "../images/".$r['filename']; if(!file_exists($myFile)) die("File doesn't exist: '{$myFile}'"); if(!is_writable($myFile)) die("File isn't writable: '{$myFile}'"); unlink($myFile) or die("Can't delete file: '{$myFile}'"); ?> What is the output from that? Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547638 Share on other sites More sharing options...
DeanWhitehouse Posted May 22, 2008 Author Share Posted May 22, 2008 Warning: unlink(/images/) [function.unlink]: No such file or directory in .... i get that error with this code $res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res); mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); $myFile = "/images/".$r['filename']; unlink($myFile) or die("can't open file"); Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547642 Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 ah...so the filename column doesn't have a value in it? or it's not finding the row. what is the value of $checked? try this out, it will skip entries without a filename specified... <?php $res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res) or die("No entry found"); mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); if(strlen($r['filename'])){ $myFile = "../images/".$r['filename']; if(!is_file($myFile)) die("File doesn't exist: '{$myFile}'"); unlink($myFile) or die("Can't delete file: '{$myFile}'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547643 Share on other sites More sharing options...
Darklink Posted May 22, 2008 Share Posted May 22, 2008 Well $r['filename'] doesn't seem to contain anything. Are you sure thats the right array key to use? Or are you sure theres data there? Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547645 Share on other sites More sharing options...
DeanWhitehouse Posted May 22, 2008 Author Share Posted May 22, 2008 ok, this one seems to work $res = mysql_query("SELECT * FROM darkflame_gallery WHERE image_id='{$checked}'") or die ("Error:" . mysql_error()); $r = mysql_fetch_assoc($res); mysql_query("DELETE FROM darkflame_gallery WHERE image_id='{$checked}'") or die("Error:" . mysql_error()); $myFile = "images/".$r['filename']; if(!file_exists($myFile)) die("File doesn't exist: '{$myFile}'"); if(!is_writable($myFile)) die("File isn't writable: '{$myFile}'"); unlink($myFile) or die("Can't delete file: '{$myFile}'"); Quote Link to comment https://forums.phpfreaks.com/topic/106826-solved-unlink-problems/#findComment-547647 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.