FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Spaces in filenames
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Spaces in filenames [message #173703 is a reply to message #173701] Sat, 30 April 2011 06:57 Go to previous messageGo to previous message
Eli the Bearded is currently offline  Eli the Bearded
Messages: 22
Registered: April 2011
Karma:
Junior Member
In comp.lang.php, 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");

Why? Just chdir() and use relative filenames. You'll save yourself
a boatload of headache.

$instdir = dirname (__FILE__);
chdir($instdir);
$fp = fopen ("./wiggy", "r");

> But what's worse, I'll also be passing $instdir to shell scripts via
> exec ().

Most people just do a half-assed job because who would ever:

# mkdir "rm -rf *;" && cd "rm -rf *;" && tar xzf /tmp/INSTALLPACKAGE.tgz

(For one thing, the "./configure && make" will typically faily
horribly.)

But if you aren't willing to cope with that, you can make things
a damn-sight easier by simply not caring where you are installed.
If you can treat it like it is your own chroot() environment and
never need to know the actual name of the install directory, you
won't care what craziness someone tries.

> 2) leave $instdir as-is, but use escapeshellarg on it whenever I need to
> pass it through exec().

Wait, you know how to escape shell characters and you are thinking
about not doing it?

> Which is the better approach?

It's a cruel world out there. Try to be prepared.

> "That excessive bail ought not to be required, nor excessive fines imposed,
> nor cruel and unusual punishments inflicted" -- Bill of Rights 1689

Don't forget the directories with control characters in them that
hide how messed up they are to the naked eye. I love those.

mkdir "<!--;rm -rf *;-->^H..17x^H..longnstalldirname" && cd \<*name && pwd

Elijah
------
protip: type each of the the ^Hs as <ctrl-V><ctrl-H>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP Runs In WinXP Command Window But Not In Browser
Next Topic: Html code beautifier
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 22:31:03 GMT 2024

Total time taken to generate the page: 0.04632 seconds