Re: Spaces in filename or path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30 April 2011 22:07, Tim Streater <tim@xxxxxxxxxxxxxxxx> wrote:
> Does it matter to PHP filesystem functions if a path/to/file/name contains spaces? IOW, is this handled OK by design or should I replaces such spaces by backslash-space or would doing that present problems?
>
> Thanks Â-- Âtim

On Windows, PHP will happily access files and directories with spaces...

<?php
file_put_contents('My name is Richard.txt', 'Hello Richard');"
?>

If you intend to pass the filename to a command line tool, then the
filename must be wrapped with double quotes ...

<?php
exec('tool.exe "My name is Richard.txt"');
?>

If you intend to pass the filename to a command line tool and the tool
has spaces in the name too, then you need to wrap both with quotes ...

<?php
exec('"C:\Program Files\tool.exe" "My name is Richard.txt"');
?>

If you are using a version of PHP before V5.3.0, please read
http://uk.php.net/manual/en/function.exec.php#101579. Your code would
need to be ...

<?php
exec('""C:\Program Files\tool.exe" "My name is Richard.txt""');
?>

I've added some _ to that so you can easily see the single and double
quotes ... (they aren't part of the real code, just there to show you
the quotes) ...

<?php
exec(_'_"_"_C:\Program Files\tool.exe_"_ _"_My name is Richard.txt_"_"_'_);
?>


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux