\ and / for linux or windows folder problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aaaaaaaa
Forum Newbie
Posts: 13
Joined: Wed Aug 19, 2009 8:43 am

\ and / for linux or windows folder problem

Post 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 :)
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: \ and / for linux or windows folder problem

Post by Weiry »

Doesnt windows recognise both \ and / for directory structures?
User avatar
turbolemon
Forum Commoner
Posts: 70
Joined: Tue Jul 14, 2009 6:45 am
Location: Preston, UK

Re: \ and / for linux or windows folder problem

Post 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!
aaaaaaaa
Forum Newbie
Posts: 13
Joined: Wed Aug 19, 2009 8:43 am

Re: \ and / for linux or windows folder problem

Post by aaaaaaaa »

Thank you for your help !
Post Reply