We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Correct syntax for subdirectories

breeze351
breeze351 asked
on
83 Views
Last Modified: 2017-03-10
If I have a site with a directory structure that looks like this:
\public_html
\Images
\test
   \Images

What should the correct syntax be if I want to access an image in the "Images" directory?  If I login to "Site\test", can I just use ".\Images\File_name"?  Will this find the file in the "public_html\Images" or the file in "public_html\test\Images"?
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:
A slash at the front of the path will go to the root directory.  No slash will be relative to the current working directory.  A dot-slash will go up one directory.  So a script in public_html/test would use something like $path = './images'; to get to the images directory that is above the test directory, and would use $path = 'images'; to get to the images below the test directory.

However, because of the way the directories are structured in the question, $path = '/images'; would have the same effect as ./images

Author

Commented:
Just so I get this correct.  If I'm in the "public_html", "Images/.." gets me the file in the root.  If I'm in "public_html/test", "Images/.." gets me the files under the test directory.
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
You're mixing up a few things.  Backslash '\' is only a directory separator in Windows.  Most browsers and Linux use the forward slash '/'.  And if you are viewing the directories from the browser, then 'public_html' has usually been the web site root directory and you can't go above that in the browser.  You can go above that on the server in PHP for example.

Author

Commented:
I know.  My last comment said:

If I'm in the "public_html", "Images/.." gets me the file in the root.  If I'm in "public_html/test", "Images/.." gets me the files under the test directory.

Didn't I have the slashes correct?
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
Depends on where you are viewing it from.  Normally from the browser and most PHP pages, you can't address 'public_html', it is assumed to be the root of the web site.  If you are in 'test', then 'Images' will get the file or directory found in 'test'.  If you want the 'Images' in the web root then you use '/Images'.

Author

Commented:
Got it.  Just use "Images/.." This would get me the images from the subdirectory  in whatever directory I'm in.
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
Yes, I believe that is correct and what I would normally do.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.