snowsquirrel Posted March 23, 2006 Share Posted March 23, 2006 I am trying to unlink a file with this name "01 doug's dog.mp3", but unlink fails, saying it can't delete "01 doug". I tried calling addslashes on the string before passing it to unlink, but this didn't seem to help at all. I would think that I wouldn't have to escape the name at all. Does unlink make an external call to command like 'rm' or 'del'. I would have thought it would just call the unix system call 'unlink', which does not need to escape the name.for example this c program runs fine:[code]#include <stdio.h>#include <unistd.h>int main(){ int rslt = unlink( "01 dougs's dog.mp3" ); printf("results was %d\n", rslt); return rslt;}[/code]yet my PHP fails:[code]unlink( "01 dougs's dog.mp3" );[/code]~S Quote Link to comment https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/ Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 I don't know for sure if this will fix it, but have you tried running addslashes on the filename before stuffing it in the unlink()? Quote Link to comment https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/#findComment-20005 Share on other sites More sharing options...
snowsquirrel Posted March 23, 2006 Author Share Posted March 23, 2006 [!--quoteo(post=357647:date=Mar 23 2006, 01:16 PM:name=snowsquirrel)--][div class=\'quotetop\']QUOTE(snowsquirrel @ Mar 23 2006, 01:16 PM) [snapback]357647[/snapback][/div][div class=\'quotemain\'][!--quotec--] I tried calling addslashes on the string before passing it to unlink, but this didn't seem to help at all. [/quote]Yes.Besides, I shouldn't need to escape it anyway, as I am not passed the string to an external command? I am just about convinced that this is a legitimate bug. Maybe tonight, I'll crack open the PHP source code.... yuck.~S Quote Link to comment https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/#findComment-20032 Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 Sorry, must have missed that part in the origional post. I'd have to say it's probably a bug as well. For the longterm if they can't get a fix, I'd suggest modifying file names as they're put on the server. Quote Link to comment https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/#findComment-20044 Share on other sites More sharing options...
snowsquirrel Posted March 23, 2006 Author Share Posted March 23, 2006 [!--quoteo(post=357694:date=Mar 23 2006, 03:07 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 23 2006, 03:07 PM) [snapback]357694[/snapback][/div][div class=\'quotemain\'][!--quotec--]I'd suggest modifying file names as they're put on the server.[/quote]I was afraid of that. ;-)Thanks,~S Quote Link to comment https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/#findComment-20081 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.