For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > November 2005 > how to reference other files?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to reference other files?
moriman

2005-11-24, 6:56 pm

Hi,

I'm having a problem referring to other files in my public_html directory ¿

Below is a short script (test.php) to show the problem...

<?php
$filename1 = "c:\\\\xitami-25\\app\\public_html\\title.php";
$filename2 = "http://home/title.php";
$filename3 = "title.php";

echo "\n";
echo $filename1."\n";
if (file_exists($filename1)){echo "found it\n";}
else {echo "not found\n";}

echo $filename2."\n";
if (file_exists($filename2)){echo "found it\n";}
else {echo "not found\n";}

echo $filename3."\n";
if (file_exists($filename3)){echo "found it\n";}
else {echo "not found\n";}
?>

both the above test.php and the file it refers to, title.php are in the same
directory.
Running the above under dos gives the following results...

c:\\xitami-25\app\public_html\title.php
found it
http://home/title.php
not found
title.php
found it

Running it under windows gives this...

c:\\xitami-25\app\public_html\title.php
found it
http://home/title.php
not found
title.php
not found

the url for the test.php is http://home/test.php
how come it doesn't find either filename2 or 3?

under dos I'm running test.php from within it's own directory. It finds
filename1 and 3.

Can someone help me to understand what is happening here?

many thanks in advance,

mori


J.O. Aho

2005-11-25, 3:55 am

moriman wrote:
> Hi,
>
> I'm having a problem referring to other files in my public_html directory ¿
>
> Below is a short script (test.php) to show the problem...
>
> <?php
> $filename1 = "c:\\\\xitami-25\\app\\public_html\\title.php";


Full paths are always found, as long as they are correct.


> $filename2 = "http://home/title.php";


The file isn't on the "local" filesystem, and therefore false.


> $filename3 = "title.php";


only true if the file is in the same directory where executed.
When executed through a webserver, then it's relative to the location of the
script.


//Aho
moriman

2005-11-25, 3:55 am

"J.O. Aho" <user@example.net> wrote in message
news:3uo2ouF10trcmU1@individual.net...
> moriman wrote:
directory ¿[color=darkred]
>
> Full paths are always found, as long as they are correct.
>

Hi,

Thx for the reply ;-)
N.B. I'm running this script through Xitami on my own poot (i.e. not hosted
elsewhere)

>
>
> The file isn't on the "local" filesystem, and therefore false.
>


The script I'm using is located (browser-wise) at http://home/test.php,
isn't a file in the same directory classed as being in the 'local'
filesystem?

>
>
> only true if the file is in the same directory where executed.
> When executed through a webserver, then it's relative to the location of

the
> script.
>


again, as above, it *is* in the same directory

sorry, still :(

mori
>
> //Aho



J.O. Aho

2005-11-25, 7:55 am

moriman wrote:

> The script I'm using is located (browser-wise) at http://home/test.php,
> isn't a file in the same directory classed as being in the 'local'
> filesystem?


No, you are going through the webserver, which isn't a local filesystem, it's
remote, no matter if the server is running on your machine or someone elses
machine.

> the
>
> again, as above, it *is* in the same directory


If your prompt in the dos-console say:

c:\

and the file is in

c:\xitami-25\app\public_html

and you execute the file

php.exe c:\xitami-25\app\public_html\test.php

then you are executing the script from another location than where the script
is located, which makes that the file title.php isn't found as it's not in c:\

but if you change directory so that you are in

c:\xitami-25\app\public_html

and execute the script with

php.exe test.php

then you have the file test.php in the same directory where you execute the
php and then you can find the file.


//Aho
moriman

2005-11-25, 7:55 am

ok, thx ;-)

mori

"J.O. Aho" <user@example.net> wrote in message
news:3uo74uF1241lsU1@individual.net...
> moriman wrote:
>
>
> No, you are going through the webserver, which isn't a local filesystem,

it's
> remote, no matter if the server is running on your machine or someone

elses
> machine.
>
of[color=darkred]
>
> If your prompt in the dos-console say:
>
> c:\
>
> and the file is in
>
> c:\xitami-25\app\public_html
>
> and you execute the file
>
> php.exe c:\xitami-25\app\public_html\test.php
>
> then you are executing the script from another location than where the

script
> is located, which makes that the file title.php isn't found as it's not in

c:\
>
> but if you change directory so that you are in
>
> c:\xitami-25\app\public_html
>
> and execute the script with
>
> php.exe test.php
>
> then you have the file test.php in the same directory where you execute

the
> php and then you can find the file.
>
>
> //Aho



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com