Understanding how to construct paths

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
Pedantic
Forum Newbie
Posts: 2
Joined: Thu May 07, 2009 1:56 pm

Understanding how to construct paths

Post by Pedantic »

I am writing code that will operate both on the Mac and on Windows boxes. As anyone knows who has worked on both platforms, Mac and Windows paths are different. If I can tell which box the client is, I can construct the path according to that box's style. How can I tell what the client is.

1.) Specifically, I am downloading using FTP in PHP. How can I tell what the platform is?

2.) When the time comes to upload, from the client, do I need any special syntax in the path to let the script know that I am downloading from the client, or will FTP figure that one out?

I have looked at the PHP site and at the PHP references I have, but none of them cover it, that I can find out. I also looked at the $_SERVER array and found nothing helpful there without a lot of parsing
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Understanding how to construct paths

Post by Yossarian »

Code: Select all

if (stristr(PHP_OS, 'WIN')) { 
 // Windows 
} else { 
 // Other 
}
Thats how you can detect it, but why do you need to rewrite paths?

I work on Win and publish to *nix and /var/www/htdocs is the same on both - they go to the root of the drive in win.
Pedantic
Forum Newbie
Posts: 2
Joined: Thu May 07, 2009 1:56 pm

Re: Understanding how to construct paths

Post by Pedantic »

Yossarian wrote:
Thats how you can detect it, but why do you need to rewrite paths?

I work on Win and publish to *nix and /var/www/htdocs is the same on both - they go to the root of the drive in win.
Yossarian:

I have years and years of experience in C++ and other languages (such as XBase), but hardly any in PHP. My newbie status on this board also reflects my status in writing PHP code.

In C++, one must take care to use the pathing style appropriate to the system. I admit that on Windows there are some concessions to Unix in that one can use either the "\" or the "/" to indicate directory level separation, but unless using the UNC, drive and path must be appropriately specified.

Thank you for the information. I will try both suggestions.

R,
Pedantic
Post Reply