Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

USING relative path or url to access folders

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

USING relative path or url to access folders

Postby imroue » Fri Oct 11, 2002 7:06 am

I am trying to use a relative path to access my folders on the webserver.
Basically, i need to be able to read any subfolder under folder MAIN and echo its contents. I am able to do this if my path is static like c:\php\blah\blah. What i need is to use the webserver directories from my isp which only give me 'public_html' as the first folder (no root)

I tried
$fp = fopen ("/public_html/blah/file.txt", "r"); -- i got an error
$fp = fopen ("http://www.example.com/", "r"); -- i got an error

Note:
allow_url_fopen (I have this set up to ON in the ini file)
User avatar
imroue
New php-forum User
New php-forum User
 
Posts: 62
Joined: Fri Oct 11, 2002 6:53 am

Re: USING relative path or url to access folders

Postby DoppyNL » Fri Oct 11, 2002 9:04 am

imroue wrote:$fp = fopen ("/public_html/blah/file.txt", "r"); -- i got an error

try this:
I'm asuming you script is located in "/"
Code: Select all
$fp = fopen (getcwd() . "public_html/blah/file.txt", "r");

imroue wrote:$fp = fopen ("http://www.example.com/", "r"); -- i got an error

This is not a file, this is a directory, you probably need the specify the file.

posting the actual error message is also very usefull for other people who try to solve you're problem

Greetz Daan
DoppyNL
 

Re: USING relative path or url to access folders

Postby imroue » Fri Oct 11, 2002 9:34 am

Thanks for your response....but i think I forgot to mention that I want to access the directories file names only.. that is why i didn't specify the file. Basically, I want to loop through the directory (i know how to do that..I Think :? ), but first I need to be able to open the directory.. MAYBE fopen is not the function i am looking for??

try this:
I'm asuming you script is located in "/"
Code: Select all
$fp = fopen (getcwd() . "public_html/blah/file.txt", "r");


This is not a file, this is a directory, you probably need the specify the file.

posting the actual error message is also very usefull for other people who try to solve you're problem

Greetz Daan[/quote]
User avatar
imroue
New php-forum User
New php-forum User
 
Posts: 62
Joined: Fri Oct 11, 2002 6:53 am

Postby Jay » Fri Oct 11, 2002 1:06 pm

Firstly, when you're accessing a file via it's web address, realise that you're calling it through HTTP and thus will only have HTTP access (ie, if you call your PHP file through the web address, you will only get the outputted contents, not the file coding itself).

Directories on the server on normally lower down in the directory structure. You can use print_r($_SERVER) to list all the server variables, one of them will show the full path root. Use this to open directories and files, it won't matter where it's being called from because it's an absolute link!
Jay
 

Postby imroue » Fri Oct 11, 2002 2:02 pm

Jay wrote:Firstly, when you're accessing a file via it's web address, realise that you're calling it through HTTP and thus will only have HTTP access (ie, if you call your PHP file through the web address, you will only get the outputted contents, not the file coding itself).

Directories on the server on normally lower down in the directory structure. You can use print_r($_SERVER) to list all the server variables, one of them will show the full path root. Use this to open directories and files, it won't matter where it's being called from because it's an absolute link!


Thanks Jay, I was able to get the absolute path.
Now I have to figure out how to read all the fileNAMES in the given directory.
User avatar
imroue
New php-forum User
New php-forum User
 
Posts: 62
Joined: Fri Oct 11, 2002 6:53 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron