Jump to content


Photo

unlink fails if filename has a quote


  • Please log in to reply
4 replies to this topic

#1 snowsquirrel

snowsquirrel
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 March 2006 - 04:16 PM

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:
#include <stdio.h>
#include <unistd.h>

int main()
{
  int rslt = unlink( "01 dougs's dog.mp3" );
  printf("results was %d\n", rslt);
  return rslt;
}
yet my PHP fails:
unlink( "01 dougs's dog.mp3" );

~S

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 04:30 PM

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()?

Info: PHP Manual


#3 snowsquirrel

snowsquirrel
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 March 2006 - 05:36 PM

[!--quoteo(post=357647:date=Mar 23 2006, 01:16 PM:name=snowsquirrel)--][div class=\'quotetop\']QUOTE(snowsquirrel @ Mar 23 2006, 01:16 PM) View Post[/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

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 06:07 PM

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.

Info: PHP Manual


#5 snowsquirrel

snowsquirrel
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 March 2006 - 07:07 PM

[!--quoteo(post=357694:date=Mar 23 2006, 03:07 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 23 2006, 03:07 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users