Web Hosting Talk







View Full Version : HTML / PHP / JS / other proper folder path question.


bow-viper1
08-18-2004, 07:51 PM
I was wondering what the proper way to link to a file in another folder was.. I heard in PHP it has to be one way, but how about CSS, or javascript or HTML. Does it matter?

For example, I have a root directory, with a "scripts" subdirectory with a file called script.js and lets say style.css

What would be the proper path to call them?

"scripts/script.js" or
"/scripts/script.js"

"scripts/style.css" or
"/scripts/style.css"

So, what is the proper way, and does it matter either way?

Corey Bryant
08-18-2004, 09:00 PM
Both should be fine. They are just different way to reference.

For example, this is called a relative hyperlink:
Originally posted by bow-viper1
"scripts/script.js"
"scripts/style.css"

And this is a virtual hyperlink:
Originally posted by bow-viper1
"/scripts/script.js"
"/scripts/style.css"

Now in ASP, you can use:
<!--#INCLUDE FILE="../nav.asp" -->
But if you want to use the virtual link:
<!--#INCLUDE VIRTUAL="/nav.asp" -->
Using a virtual hyperlink can be good from time to time if you are adding / deleting folders. The virtual hyperlinks takes it back to the root.

Marble
08-19-2004, 03:26 AM
You will also run into a server thinking /somepath/dir/file.php is not where you would expect it. It will think "/" means root. In that case use "./somepath/dir/file.php" or just "somepath/dir/file.php" which is the same thing. ./ means current dir, ../ means go up one dir.

Marque
08-19-2004, 12:40 PM
Ok, here is a general breakdown.

There are two different types of directory paths. RELATIVE and ABSOLUTE.

A Relative path would be considered as anything pertaining to the current directory that your in, or the directory your starting to navigate from. A Absolute path always starts from the root, or tree beginning.

These are the same (Relative Path):

./scripts/blah.html
scripts/blah.html

This is an Absolute Path:

/home/username/public_html/scripts/blah.html

Now, if you do not want to use an absolute path, and want to navigate one directory up the tree, you would use:

../scripts/blah.html

So to cover:

./scripts/ means "Start in this directory, and go into the scripts directory"
../scripts/ means "Go back one direcory and go into the scripts directory"
/home/usr/www/scripts means "start from the root and navigate through the listed directories and into the scripts directory."

If you are going to be including a common file into different scripts in different directories, the best bet is to use an absolute path, that way you dont have to change the variable everytime you include the script.

Hope this helps!

Corey Bryant
08-19-2004, 12:43 PM
Marque, I always thought that
/home/username/public_html/scripts/blah.html
was an virtual path, and
http://www.yourdomain.com/scripts/blah.html
was an absolute path

Marble
08-19-2004, 12:59 PM
using http://www.yourdomain.com/scripts/blah.html as a path will make an http request everytime you access that file / img... Not the most efficient method.

Using paths within the server directory is the best way.

Marque
08-19-2004, 01:12 PM
Originally posted by coreybryant
Marque, I always thought that
http://www.yourdomain.com/scripts/blah.html
was an absolute path

In terms of referencing a image, or a link to a page, yes..that is an absolute path.

But I was speaking in terms of *nix navigation when making includes to external files while writing scripts/programs, an absolute path begins from the root directory.

As for "virtual paths", Ive only heard that term in reference to ASP programming, but I could be wrong :D

Corey Bryant
08-19-2004, 02:07 PM
Cool. No worries. I don't deal with PHP myself so maybe that is why I am on that mindset? :)