|
Posted by laredotornado@zipmail.com on August 4, 2008, 3:23 pm
Please log in for more thread options > .oO(laredotorn...@zipmail.com)
>
> >I'm using PHP 5 on Linux. =A0I have a function that checks for file type
> >by doing the following:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$cmd =3D "file $p_input_file";
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0exec("$cmd 2>&1", $output, $return);
>
> >However if the file "$p_input_file" contains spaces, the command
> >doesn't work properly (I would need to insert a "\" before the space
> >for it to work). =A0I figure there are probably some other characters in
> >the file name that would screw up the command. =A0Is there a predefined
> >way of escaping the file names or do I need to just do a generic
> >search and replace on all the special characters I can think of?
>
> escapeshellarg()
> escapeshellcmd()
>
> Micha
Thanks but I think I'm still doing something wrong. I have
$p_input_file =3D "/home/me/Toad Getting Started
Guide.pdf";
$cmd =3D escapeshellcmd("file $p_input_file");
print "cmd: $cmd<BR>\n"; # outputs 'cmd: file /home/
me/Toad Getting Started Guide.pdf'
Shouldn't the command print out as
cmd: file /home/laredotornado/Toad\ Getting\ Started\ Guide.pdf
? - Dave
|