Atheer
Atheer

Reputation: 921

how can i access a folder or file in parent folder php

i want a shared folder which contains images to be accessed by html pages inside sub folders.(child folders)

Upvotes: 2

Views: 31622

Answers (5)

SLaks
SLaks

Reputation: 887469

Make a folder inside your website and put images into it.

Upvotes: 7

Zuul
Zuul

Reputation: 16269

If I got it right, you have a folder with many folders inside, and inside does many folder you have html pages, and you want does pages to access the first folder...

main_folder

pic.png

pic.gif

pic.jpg

sub_folder

html_page.php

just use ../pic.png when you call the image file from the html_page.php

Was this what you where looking for ?

Upvotes: 1

Colonel Sponsz
Colonel Sponsz

Reputation: 1721

You can get the directory of the current file with the dirname funciton:

dirname(__FILE__)

If you want the parent directory you can use '..' thus:

$current_dir = dirname(__FILE__);
$parent_dir = $current_dir.'/..';

Upvotes: 0

Tesserex
Tesserex

Reputation: 17314

If you mean your html folder and images folder are siblings, you're probably looking for the .. directory... um, thingy.

Your files look like:

/www
    /html
        index.php
    /images
        myimage.png

Write an img tag like this:

<img src="../images/myimage.png" />

Upvotes: 11

Konerak
Konerak

Reputation: 39763

Basically, there are two ways of linking to a resource (page/script/image/whatever):

  • Use an absolute link: http://www.yourserver.com/path/to/resource.jpg
  • Use a relative link: for example, to go from http://www.yourserver.com/path/from/page.html to http://www.yourserver.com/path/to/resource.jpg, you use ../to/resource.jpg

So just put your images on a publicly accessibly folder, and refer to them using one of those two methods.

Or refine your question :)

Upvotes: 1

Related Questions