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); Quote Link to comment 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); Quote Link to comment 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); Quote Link to comment 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? Quote Link to comment 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!"; } ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 chmod 777 foldername Quote Link to comment 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!"; } ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
dangeorge6 Posted February 14, 2007 Author Share Posted February 14, 2007 works, you guys rock Quote Link to comment 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 Quote Link to comment 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.