dangeorge6 Posted February 14, 2007 Share Posted February 14, 2007 I need to be able to delete mp3s from a directory. I'm using unlink like so: unlink($path_to_delete); Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/ Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 Ok, so what's the problem? Make sure that you have error reporting turned on.... ini_set("display_errors", 1); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184132 Share on other sites More sharing options...
realjumper Posted February 14, 2007 Share Posted February 14, 2007 $myFile = "path_to_file/file.jpg"; unlink($myFile); Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184134 Share on other sites More sharing options...
dangeorge6 Posted February 14, 2007 Author Share Posted February 14, 2007 Jeez...half my post got cut for some reason Here's the error: Warning: unlink(http://MYURL/Beatles%20-%20It's%20Getting%20Better%20All%20The%20Time.mp3): No such file or directory in /var/www/web2/web/musicproject/php_scripts/functions.php on line 34 This link does exist, i've tried it with %20 and just spaces and same error. Is this a permissions thing? If so, how can I safely make this work? Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184135 Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 try this it works ok first try the script in the same directory. <?php $file_to_unlink="delete_me.php"; if(unlink("$file_to_unlink")){ echo "$file_to_unlink deleted"; }else{ echo "sorry but the file $file_to_unlink has not been deleted!"; } ?> Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184144 Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 You can't unlink a file that's a website...which is what it interprets the http:// to mean. You have to give it a local path. Use realpath: http://www.php.net/realpath Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184146 Share on other sites More sharing options...
dangeorge6 Posted February 14, 2007 Author Share Posted February 14, 2007 thanks hitman. Now I get a permission denied. Perhaps this is out of the scope of the board. But how do I give php permission to delete a folder on my apache server? What's safest way to do this so I don't get hacked Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184155 Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 what on win linux what? linux 777 win nothink as long as your the admin. Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184171 Share on other sites More sharing options...
dangeorge6 Posted February 14, 2007 Author Share Posted February 14, 2007 i run apache on ubuntu linux. how do you give delete privileges to specific folder on a website? Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184174 Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 chmod 777 foldername Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184176 Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 My PHP script refused to delete read-only files (which is probably a good thing), but I couldnt find out how to fix this on windows. The solution is simple, i just replaced <?php @unlink( $entry ); ?> with: <?php @chmod( $entry, 0777 ); @unlink( $entry ); ?> chmod isnt supposed to work on windows, but 0777 seems to clear the read only flag, and 0444 seems to set the read only flag. <?php $file_to_unlink="delete_me.php"; @chmod( $file_to_unlink, 0777 ); if(@unlink("$file_to_unlink")){ echo "$file_to_unlink deleted"; }else{ echo "sorry but the file $file_to_unlink has not been deleted!"; } ?> Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184187 Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 You may not want to have the "@" before your command names while you are testing...it will suppress any errors. Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184190 Share on other sites More sharing options...
dangeorge6 Posted February 14, 2007 Author Share Posted February 14, 2007 works, you guys rock Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184193 Share on other sites More sharing options...
utexas_pjm Posted February 14, 2007 Share Posted February 14, 2007 chmod 777 foldername Depending on how sensitive the data is in the folder you might want to % sudo chown apacheUser:apacheUser foldername -R , where apacheUser := the user that your run you webserver as. Best, Patrick Link to comment https://forums.phpfreaks.com/topic/38397-unlink-problem/#findComment-184270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.