Jump to content

unlink fails if filename has a quote


snowsquirrel

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
Link to comment
https://forums.phpfreaks.com/topic/5609-unlink-fails-if-filename-has-a-quote/
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
[!--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

Archived

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

×
×
  • Create New...

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.