how to reference other files?

This is a discussion on how to reference other files? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I'm having a problem referring to other files in my public_html directory ¿ Below is a short script (test....


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-24-2005
moriman
 
Posts: n/a
Default how to reference other files?

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


Reply With Quote
  #2 (permalink)  
Old 11-25-2005
J.O. Aho
 
Posts: n/a
Default Re: how to reference other files?

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
Reply With Quote
  #3 (permalink)  
Old 11-25-2005
moriman
 
Posts: n/a
Default Re: how to reference other files?

"J.O. Aho" <user@example.net> wrote in message
news:3uo2ouF10trcmU1@individual.net...
> 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.
>

Hi,

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

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

>
> 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?

>
> > $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.
>


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

sorry, still confused :(

mori
>
> //Aho



Reply With Quote
  #4 (permalink)  
Old 11-25-2005
J.O. Aho
 
Posts: n/a
Default Re: how to reference other files?

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.

>>> $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.
>>

>
> 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
Reply With Quote
  #5 (permalink)  
Old 11-25-2005
moriman
 
Posts: n/a
Default Re: how to reference other files?

ok, thx ;-)

mori

"J.O. Aho" <user@example.net> wrote in message
news:3uo74uF1241lsU1@individual.net...
> 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.
>
> >>> $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.
> >>

> >
> > 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



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:04 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0