The BoardMod Project
 The Project | News | Downloads | Mods | FAQ | Templates | Chat | Forum
BoardMod Support Forum
[ Home | Help | Search | Login | Register ]  

20.06.13 at 06:28:17, Welcome, Guest. Please Login or Register

Choose Language:
Pages: 1 2 3 4
How Paths Work (Read 20095 times)
Dave Baughman
VIP
*****
Offline

Murfreesboro, Tennessee, USA
Posts: 2039



24.08.01 at 02:57:31  
How Paths Work:

This tutorial is going to explain a bit more about how paths work and what symbols mean within the path. To begin the tutorial, we'll setup a directory tree scenario like you might find on your webhost.

When I login to my site with my favorite ftp client, I see two folders: public_html and private. Files inside the 'private' folder are not viewable over the web, but may be access from scripts running on my website. Files inside 'public_html' are viewable over the web as long as I dont reset their permissions to be restricted.

My main page is named index.html. The url to it will be http://www.daveb.com/index.html. The absolute path to it will be /www/daveb/public_html/index.html. Now, inside my public_html folder, I have my cgi-bin, where I keep all my scripts. Inside the cgi-bin, I like to make seperate folders to keep scripts and their files organized. Today we'll be using a script named 'readfile.pl' inside the 'misc' folder in my cgi-bin. So the url to the script would be http://www.daveb.com/cgi-bin/misc/readfile.pl and the absolute path would be /www/daveb/public_html/cgi-bin/misc/readfile.pl.

My readfile script needs to know the path to a file called 'readme.txt' so it can read it and print the output to a page for me. However, to read from the file, I have to tell it where the file is. This is normally done using an open(FILE, "/path/to/file"); type statement (in YaBB, fopen is used, which is a sub routine written to include both the open command and the file locking procedures all in one). Now my only problem is figuring out the correct path to my file. My file is located in a folder named 'mydocs' which is in the public_html directory. The url to 'mydocs' is http://www.daveb.com/mydocs and the absolute path is /www/daveb/public_html/mydocs.

The easiest way to tell the script where the file is located is to give it the full absolute path to the file. In this case, that is /www/daveb/public_html/mydocs/readme.txt. However, maybe you are too lazy to type all that and you want to use relative paths. Here are some examples of relative paths I could put into the readfile.pl script to have it try and locate the readme.txt file so it can read from it. I'll give examples of several different types of paths, and where the script would be expecting to find the file if it was given each of these paths.

Code:
Path Given: 'readme.txt'
Url: 'http://www.daveb.com/cgi-bin/misc/readme.txt'
Absolute Path: '/www/daveb/public_html/cgi-bin/misc/readme.txt'

Since my readme.txt file is in the 'mydocs' folder, this path is incorrect for my script. If you only give the script the filename, it will look for the file in the same directory that the script is running in).

Code:
Path Given: './readme.txt'
Url: 'http://www.daveb.com/cgi-bin/misc/readme.txt'
Absolute Path: '/www/daveb/public_html/cgi-bin/misc/readme.txt'

This path returns the same result as the one above. './' means current directory. This would also be incorrect for my script.

Code:
Path Given: '../readme.txt'
Url: 'http://www.daveb.com/cgi-bin/readme.txt'
Absolute Path: '/www/daveb/public_html/cgi-bin/readme.txt'

This path is wrong for my script, too. '../' means to move up one directory within the directory heirachy. This tells the script that the file is one directory up from where the script is currently located, which would be the cgi-bin in this case.

Code:
Path Given: '/readme.txt'
Url: 'N/A'
Absolute Path: '/www/daveb/readme.txt'

Once again, this path is wrong for me. By putting only a '/' in front of my filename, the script thinks the file is located in the highest directory in my directory heirarchy. In my case, this is outside of my public webspace. For many people who dont have access to any folders outside of their public webspace with their hosts, '/readme.txt' would mean that the readme.txt was located in their main folder (the first folder you see when you login to your ftp, normally).

Code:
Path Given: '../../readme.txt'
Url: 'http://www.daveb.com/readme.txt'
Absolute Path: '/www/daveb/public_html/readme.txt'

I'm getting closer now, but still wrong. Ive gone up TWO directories from the script this time, which lands me trying to read the file from the public_html folder.

Code:
Path Given: '../../mydocs/readme.txt'
Url: 'http://www.daveb.com/mydocs/readme.txt'
Absolute Path: '/www/daveb/public_html/mydocs/readme.txt'

Ah yes, sweet success. I back out two directories from where the script is located. Now that Im within the public_html directory, I can tell the script to go back into any folders located with public_html. And, what luck, 'mydocs' folder is located there.

Code:
Path Given: '/public_html/mydocs/readme.txt'
Url: 'http://www.daveb.com/mydocs/readme.txt'
Absolute Path: '/www/daveb/public_html/mydocs/readme.txt'

Hey, this works, too. The beginning '/' lets the script know Im starting from the highest directory, and then I just work my way down the path.

Now, lets say I wanted to stick the readme.txt file in the 'private' folder so that it's not accessible over the web. Well, I could do a few paths. See if you can figure them out.

If you said any of these, then you are right:
'/www/daveb/private/readme.txt'
'/private/readme.txt'
'../../../private/readme.txt'

Now here's something to leave you with. Figure out where this path would be looking for the readme.txt file from the readfile.pl script:

./../../cgi-bin/../../private/../public_html/mydocs/../readme.txt

Well, while that's a ridiculous way to go about it, that would put the file at:
Code:
Url: 'http://www.daveb.com/readme.txt'
Absolute Path: '/www/daveb/public_html/readme.txt'


Hope that helps you in all your path questions.

- DaveB
 
IP Logged
 

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Shoeb Omar
Mod Writer
*****
Offline

San Diego, California, USA
Posts: 5665



Reply #1 - 24.08.01 at 08:52:20  
THANK YOU!!!!!!!!!!  Grin
 
IP Logged
 

YaBB SP2 BETA!
Now taking pay jobs in PHP or Perl.  Contact me for details.
DemonSlayer
Hacker God
*****
Offline

Posts: 1398



Reply #2 - 30.08.01 at 04:31:55  
Now i am definetely sure of paths Smiley
 
IP Logged
 
David
Bloody Novice
*
Offline

Posts: 4



Reply #3 - 15.09.01 at 05:20:43  
Ok, but my message board is currently at F2S, because my domain isn't ready yet. How would paths there work?
 
IP Logged
 

David Peer
Dave Baughman
VIP
*****
Offline

Murfreesboro, Tennessee, USA
Posts: 2039



Reply #4 - 15.09.01 at 05:31:08  
Exactly the same way. You can login to your F2S account and view your absolute path to your directory, but this tutorial is explaining mostly how relative paths work, and they apply for any system/server that is running a Unix or smiliar *nix operating system.
 
IP Logged
 

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Shadow_FCF
Bloody Novice
*
Offline

Posts: 4



Reply #5 - 24.11.01 at 06:14:58  
so if this is the url to my avatars folder:

www.shadowopz.com/YaBBImages/avatars

this would be the path:?

/www/shadowopz/public_html/YaBBImages/avatars

if yes, then why the heck isn't it working?

--Shadow
 
IP Logged
 

[glow=green,2,300]--Shadow |FCF| [/glow]
Shadow Opz
SO Forums
DemonSlayer
Hacker God
*****
Offline

Posts: 1398



Reply #6 - 24.11.01 at 07:31:17  
Because different servers have different paths
 
IP Logged
 
Shadow_FCF
Bloody Novice
*
Offline

Posts: 4



Reply #7 - 24.11.01 at 07:33:10  
dangit, I emailed my server, hopefully they can help, thanks.

--Shadow
 
IP Logged
 

[glow=green,2,300]--Shadow |FCF| [/glow]
Shadow Opz
SO Forums
Kickboy12
Hacker Expert
****
Offline

Posts: 326



Reply #8 - 01.12.01 at 06:21:58  
i used ../../www/YaBBImages/avatars
yous might be different.

maybe like this:
../../www/shadowopz/public_html/YaBBImages/avatars

just an idea  Smiley
 
IP Logged
 
kristhebelgian
Bloody Novice
*
Offline

Posts: 1



Reply #9 - 12.03.02 at 18:56:32  
My avatar url is this: http://sc.getduffed.com/public_html/yabbimages/avatars

What's my path then?
 
IP Logged
 
Michael Prager
Mod God
*****
Offline

Germany, Hessen, Germany
Posts: 6331



Reply #10 - 12.03.02 at 19:01:32  
Shadow_FCF wrote on 24.11.01 at 06:14:58:
so if this is the url to my avatars folder:

www.shadowopz.com/YaBBImages/avatars

this would be the path:?

/www/shadowopz/public_html/YaBBImages/avatars

if yes, then why the heck isn't it working?

--Shadow

try /www/shadowopz/public_html/yabbimages/avatars
 
IP Logged
 


...  
 _____                   _  _____         _
| __  | ___  ___  ___  _| ||     | ___  _| |
| __ -|| . || .'||  _|| . || | | || . || . |
|_____||___||__,||_|  |___||_|_|_||___||___|
Dave Baughman
VIP
*****
Offline

Murfreesboro, Tennessee, USA
Posts: 2039



Reply #11 - 13.03.02 at 05:59:37  
Please remember that it's nearly impossible to look at a URL and determine the absolute path the URL is following, because absolute paths can differ on every server, depending on how their server's directory system is setup.
 
IP Logged
 

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Christer Alexander
FAQ Writer
*****
Offline

Lethbridge, Alberta, Canada
Posts: 3443



Reply #12 - 15.04.02 at 14:40:19  
on some big servers, they use /home/(username)

you may wanna try that, or : /home/(username)/www
 
IP Logged
 

Code:
 
unless(0) { stab("LoonyPandora"); next; }
Dave Baughman
VIP
*****
Offline

Murfreesboro, Tennessee, USA
Posts: 2039



Reply #13 - 15.04.02 at 14:48:42  
Your best bet is just to install the Absolute Path Finder mod from the mod section. It will save you a lot of guesswork.
 
IP Logged
 

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Christer Alexander
FAQ Writer
*****
Offline

Lethbridge, Alberta, Canada
Posts: 3443



Reply #14 - 15.04.02 at 15:59:27  
hehe...advertising a little for your mods, dave?
 
IP Logged
 

Code:
 
unless(0) { stab("LoonyPandora"); next; }
Pages: 1 2 3 4
© 2000-2012 by - All rights reserved.

Project website hosting proudly sponsored and provided by UK2 Hosting
 The Project | News | Downloads | Mods | FAQ | Templates | Chat | Forum