Page Index Toggle Pages: [1] 2 3 4 Send TopicPrint
Very Hot Topic (More than 25 Replies) How Paths Work (Read 13473 times)
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
How Paths Work
Aug 24th, 2001 at 1:57am
Print Post  
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'[/code]
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'[/code]
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'[/code]
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'[/code]
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'[/code]
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'[/code]
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'[/code]
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'[/code]

Hope that helps you in all your path questions.

- DaveB
  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Shoeb Omar
God Member
*****
Offline


Mod Writer

Posts: 5665
Location: San Diego
Joined: Jun 29th, 2001
Gender: Male
Re: How Paths Work
Reply #1 - Aug 24th, 2001 at 7:52am
Print Post  
THANK YOU!!!!!!!!!!  Grin
  

YaBB SP2 BETA!
Now taking pay jobs in PHP or Perl.  Contact me for details.
Back to top
IP Logged
 
DemonSlayer
God Member
*****
Offline


I am the face of pure
evil!

Posts: 1398
Joined: Jul 26th, 2001
Gender: Male
Re: How Paths Work
Reply #2 - Aug 30th, 2001 at 3:31am
Print Post  
Now i am definetely sure of paths Smiley
  
Back to top
ICQAIM  
IP Logged
 
David
New Member
*
Offline


Babies...can't stand them

Posts: 4
Joined: Sep 15th, 2001
Gender: Male
Re: How Paths Work
Reply #3 - Sep 15th, 2001 at 4:20am
Print Post  
Ok, but my message board is currently at F2S, because my domain isn't ready yet. How would paths there work?
  

David Peer
Back to top
 
IP Logged
 
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
Re: How Paths Work
Reply #4 - Sep 15th, 2001 at 4:31am
Print Post  
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.
  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Shadow_FCF
New Member
*
Offline


death is only the beginning

Posts: 4
Joined: Nov 24th, 2001
Re: How Paths Work
Reply #5 - Nov 24th, 2001 at 6:14am
Print Post  
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
  

[glow=green,2,300]--Shadow |FCF| [/glow]
Shadow Opz
SO Forums
Back to top
WWW  
IP Logged
 
DemonSlayer
God Member
*****
Offline


I am the face of pure
evil!

Posts: 1398
Joined: Jul 26th, 2001
Gender: Male
Re: How Paths Work
Reply #6 - Nov 24th, 2001 at 7:31am
Print Post  
Because different servers have different paths
  
Back to top
ICQAIM  
IP Logged
 
Shadow_FCF
New Member
*
Offline


death is only the beginning

Posts: 4
Joined: Nov 24th, 2001
Re: How Paths Work
Reply #7 - Nov 24th, 2001 at 7:33am
Print Post  
dangit, I emailed my server, hopefully they can help, thanks.

--Shadow
  

[glow=green,2,300]--Shadow |FCF| [/glow]
Shadow Opz
SO Forums
Back to top
WWW  
IP Logged
 
Kickboy12
Senior Member
****
Offline



Posts: 326
Joined: Nov 5th, 2001
Gender: Female
Re: How Paths Work
Reply #8 - Dec 1st, 2001 at 6:21am
Print Post  
i used ../../www/YaBBImages/avatars
yous might be different.

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

just an idea  Smiley
  
Back to top
YIMAIM  
IP Logged
 
kristhebelgian
New Member
*
Offline


I love YaBB 1G - SP1!

Posts: 1
Joined: Mar 12th, 2002
Re: How Paths Work
Reply #9 - Mar 12th, 2002 at 6:56pm
Print Post  
My avatar url is this: http://sc.getduffed.com/public_html/yabbimages/avatars

What's my path then?
  
Back to top
 
IP Logged
 
Administrator
Forum Administrator
*****
Offline


Yummm

Posts: 7
Location: Modders Rile
Joined: Oct 7th, 2014
Gender: Male
Re: How Paths Work
Reply #10 - Mar 12th, 2002 at 7:01pm
Print Post  
Shadow_FCF wrote on Nov 24th, 2001 at 6:14am:
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
  

The Administrator.
Back to top
WWW  
IP Logged
 
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
Re: How Paths Work
Reply #11 - Mar 13th, 2002 at 5:59am
Print Post  
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.
  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: How Paths Work
Reply #12 - Apr 15th, 2002 at 1:40pm
Print Post  
on some big servers, they use /home/(username)

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

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
Dave Baughman
God Member
*****
Offline


I want my MTV

Posts: 2039
Location: Murfreesboro
Joined: May 18th, 2001
Gender: Male
Re: How Paths Work
Reply #13 - Apr 15th, 2002 at 1:48pm
Print Post  
Your best bet is just to install the Absolute Path Finder mod from the mod section. It will save you a lot of guesswork.
  

I'm not sure if it's ignorance or apathy, but I don't know and I don't care.
Back to top
WWW  
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: How Paths Work
Reply #14 - Apr 15th, 2002 at 2:59pm
Print Post  
hehe...advertising a little for your mods, dave?
  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 3 4
Send TopicPrint