Re: Spaces in filenames [message #173702 is a reply to message #173701] |
Sat, 30 April 2011 01:26 |
Robert Heller
Messages: 60 Registered: December 2010
Karma:
|
Member |
|
|
At Sat, 30 Apr 2011 00:00:50 +0100 Tim Streater <timstreater(at)waitrose(dot)com> wrote:
>
> When my app starts up, it discovers where it has been installed using:
>
> $instdir = dirname (__FILE__);
>
> Now, I have no control over where this might be in the file system, and
> the user may well put it somewhere such that the path contains spaces.
> I'm passing this round the app, and in the fullness of time may be doing
> things like:
>
> $fp = fopen ($instdir . "/wiggy", "r");
>
> Does it matter to PHP filesystem functions if the filename contains
> spaces?
>
> But what's worse, I'll also be passing $instdir to shell scripts via
> exec ().
>
> Seems to me I can:
>
> 1) search/replace $instdir to escape spaces with backslash-space. But
> does this mess up PHP filesystem functions?
Most likely.
>
> 2) leave $instdir as-is, but use escapeshellarg on it whenever I need to
> pass it through exec().
This is the approach.
OTOH, you really should not be using exec() at all -- it is a security
risk.
Note furthur: it is more likely that your PHP code will be installed on
a UNIX (Linux) system (eg a LAMP box) and Linux sysadmins (and many
users) tend to avoid spaces in file pathnames, esp. on servers. You may
be chasing a problem that is not going to be an issue.
>
> Which is the better approach?
>
--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
|
|
|