Jump to content

Archived

This topic is now archived and is closed to further replies.

snowsquirrel

unlink fails if filename has a quote

Recommended Posts

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

Share this post


Link to post
Share on other sites
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()?

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.