upendra470 Posted August 31, 2011 Share Posted August 31, 2011 I want to delete an image file from a folder using unlink. The code is : $movie_id = $checkbox[$i]; $sql = "DELETE from movie_basic_details where `movie_id` = '$movie_id'"; $result = mysql_query($sql) or die(mysql_error()); $sql1 = "DELETE from movie_details where `movie_id` = '$movie_id'"; $result = mysql_query($sql1) or die(mysql_error()); $sql2 = "DELETE from movie_stars where `movie_id` = '$movie_id'"; $result = mysql_query($sql2) or die(mysql_error()); $query = "select movie_name from movie_basic_details where movie_id = '$movie_id'"; $res = mysql_query($query) or die(mysql_error()); $data = mysql_fetch_array($res); unlink("upload/movies/".$data['movie_name']); } The entries in the database have been deleted but only the image corresponds to that entry do not get deleted. The following warning comes up : Warning: unlink(upload/movies/) [function.unlink]: Permission denied in C:\wamp\www\ContentPanel\deletemovies.php on line 23 I have uploaded the files using $_FILES server variable and move_uploaded_file function. I am running this script on windows 7. Please Help. Quote Link to comment https://forums.phpfreaks.com/topic/246113-unlink-permission-denied/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2011 Share Posted August 31, 2011 Warning: unlink(upload/movies/ ) $data['movie_name'] is empty ^^^^ (there's no file name in the error message showing what unlink was trying to do), because you have already deleted the row from your table in the first DELETE query and the last SELECT query returns zero rows. Quote Link to comment https://forums.phpfreaks.com/topic/246113-unlink-permission-denied/#findComment-1263937 Share on other sites More sharing options...
upendra470 Posted August 31, 2011 Author Share Posted August 31, 2011 Thanks alot. I should have concentrated on my code . I interchange the last four lines and it worked. Thanks once again. Quote Link to comment https://forums.phpfreaks.com/topic/246113-unlink-permission-denied/#findComment-1263939 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.