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....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
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 |
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|