luvlemonade Posted July 30, 2007 Share Posted July 30, 2007 im trying to delete files name from database but the file isnt deleted from directory, i have heard about unlink function, but i dunno how it works, can anybody show me the way? thanks in advant Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/ Share on other sites More sharing options...
HaLo2FrEeEk Posted July 30, 2007 Share Posted July 30, 2007 unset(filename); make sure you navigate to the right directory first to delete. for example, $filename = // Code to get the filename from the database unset($filename); Simple as that, Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-310627 Share on other sites More sharing options...
hvle Posted July 30, 2007 Share Posted July 30, 2007 You may not have permission to delete the file. It seems like you're trying to delete from php, and you should be aware that php usually running as least privileges user on most system. Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-310675 Share on other sites More sharing options...
luvlemonade Posted July 31, 2007 Author Share Posted July 31, 2007 this is the code i made : $foto = $row['foto']; $filename = dirname(__FILE__).'/../catalogue_images/'.$foto; unset($filename); but it doesnt affect anything, i think the dirname i made is wrong, can u help me fix it. Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-311715 Share on other sites More sharing options...
calabiyau Posted July 31, 2007 Share Posted July 31, 2007 $foto = $row['foto']; $path_to_file = "../catalogue_images/".$foto; unlink($path_to_file); That should work if permissions are set...just make sure to get the path correct...it is relative to where the running script is located. So if it is located one level above that then you have ../catalogue_images if it is a folder within the same directory as the script it is simply "catalogue_images/".$foto Sorry if you already know that stuff, but maybe you don't Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-311716 Share on other sites More sharing options...
Vizor Posted July 31, 2007 Share Posted July 31, 2007 PHP won't delete a directory if there are files in it. Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-311740 Share on other sites More sharing options...
luvlemonade Posted July 31, 2007 Author Share Posted July 31, 2007 dont be sorry but i dunno how to set permission would u tell me? Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-311749 Share on other sites More sharing options...
Vizor Posted July 31, 2007 Share Posted July 31, 2007 chown and chmod. Quote Link to comment https://forums.phpfreaks.com/topic/62413-deleting-file-from-a-directory/#findComment-311755 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.