Page 1 of 1

\ and / for linux or windows folder problem

Posted: Thu Sep 10, 2009 3:34 am
by aaaaaaaa
Hey !

I want to move files to, for example using $temp_folder as a destination,

Code: Select all

$temp_folder = sys_get_temp_dir()."/".rand()."/";
but actually, / is for *ux and \ for windows. I would like my php code to work on any OS.
I use php on command line :

Code: Select all

php myApplication.php
in the console, but not Apache or other software.

I think it's a common problem and many topics has been posted on the web, but I haven't found any so far (wrong choice of keywords? wrong method?)
Anyway, thank in advance :)

Re: \ and / for linux or windows folder problem

Posted: Thu Sep 10, 2009 4:52 am
by Weiry
Doesnt windows recognise both \ and / for directory structures?

Re: \ and / for linux or windows folder problem

Posted: Thu Sep 10, 2009 4:56 am
by turbolemon
DIRECTORY_SEPARATOR constant is defined in PHP. Obviously this is massive in comparison to "/", so you can re-define it to something more useful like:

Code: Select all

 
define('DS',DIRECTORY_SEPARATOR);
$temp_folder = sys_get_temp_dir().DS.rand().DS;
 
Hope that helps!

Re: \ and / for linux or windows folder problem

Posted: Thu Sep 10, 2009 9:02 am
by aaaaaaaa
Thank you for your help !