Re: File Handing Windows / Linux
| From: | Ing. Ivo F.A.C. Fokkema | Date: | Wed, 17 Nov 2004 14:32:36 +0000 |
| Subject: | Re: File Handing Windows / Linux | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202301@lists.php.net to get a copy of this message | ||
On Sun, 14 Nov 2004 18:21:23 +0100, M. Sokolewicz wrote:
> Steve Vernon wrote:
>
>> Hiya!
>>
>> I am trying to make some code which gets a handle to a directory, but
>> has different code for my localhost (Windows) and for online (Linux
>> server).
>>
>> Basically, I want either of the below lines. Say if the first fails, it
>> must be on Linux and then it uses the line below.
>>
>> The two example lines are:
>>
>> @ $handle =
>>
>> opendir("c:/websites/mywebsite/extra/photos/".$_GET['page']."/");
>> @ $handle =
>>
>> opendir("/home/mywebsite/public_html/extra/photos/".$_GET['page']."/");
>>
>> Had a search on google, but not really sure what to look for!
>>
>> Love,
>>
>> Steve
>> XxX
>
> if(false === ($handle =
>
> opendir("c:/websites/mywebsite/extra/photos/".$_GET['page']."/"))) {
> $handle =
>
> opendir("/home/mywebsite/public_html/extra/photos/".$_GET['page']."/");
> }
IMHO, it would be better to check the constant PHP_OS for the current OS
or check the current $_SERVER['HTTP_HOST'] to find out whether you are on
your local windows server or the linux server. So (not tested)
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
@ $handle =
opendir("c:/websites/mywebsite/extra/photos/".$_GET['page']."/");
} else {
@ $handle =
opendir("/home/mywebsite/public_html/extra/photos/".$_GET['page']."/");
}
HTH,
Ivo