Avatar of breeze351
breeze351

asked on 

Correct syntax for subdirectories

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"?
PHP

Avatar of undefined
Last Comment
breeze351
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of breeze351
breeze351

ASKER

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.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.
Avatar of breeze351
breeze351

ASKER

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?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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'.
Avatar of breeze351
breeze351

ASKER

Got it.  Just use "Images/.." This would get me the images from the subdirectory  in whatever directory I'm in.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Yes, I believe that is correct and what I would normally do.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of breeze351
breeze351

ASKER

Thanks
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo