SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: problem in path

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem in path

    Hi,


    I need some help about the path i don't know how can i access this in php

    this is the path c:\wamp\www\first_folder\second_folder\third_folder\image.jpg


    src="../third_folder/image.jpg"

    but i could not display the image...what is the correct way in accessing my image thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    It depends where the code is relative to the image. In what folder is the code file stored that contains src="../third_folder/image.jpg" ?

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    It depends where the code is relative to the image. In what folder is the code file stored that contains src="../third_folder/image.jpg" ?
    The php code is in the first_folder and the image.jpg is in the third_folder.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jemz View Post
    The php code is in the first_folder and the image.jpg is in the third_folder.
    Then try
    Code:
    src="second_folder/third_folder/image.jpg"

  5. #5
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Then try
    Code:
    src="second_folder/third_folder/image.jpg"
    why not like this
    src="../second_folder/third_folder/image.jpg" ?

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jemz View Post
    why not like this
    src="../second_folder/third_folder/image.jpg" ?
    Why would you want to add '../' ? Do you know what that means?

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Why would you want to add '../' ? Do you know what that means?
    Hi, sorry for the late reply,to be honest i don't know what this means "../",can you please enlighten my mind on what it means.

    By the way it's working i tried your solution thank you so much for helping me.

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If this is the real path of your files...

    c:\wamp\www\first_folder\second_folder\third_folder\image.jpg

    And the home page of your website is served from :

    c:\wamp\www\

    Then your html should reference it from that home page by adding a slash before the path of the requested file :

    <img src = "/fiirst_folder/second_folder/third_folder/image.jpg" />

    Then it matters naught where the webpage is served from on that website.

    You need to read up on the difference between relative and absolute path.

    ps

    ../ means go up one directory from where I am now.

    ../images means go up one directory from where I am now, then go down into a directory called images

    These are relative links (relative to where I am now)

  9. #9
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    If this is the real path of your files...

    c:\wamp\www\first_folder\second_folder\third_folder\image.jpg

    And the home page of your website is served from :

    c:\wamp\www\

    Then your html should reference it from that home page by adding a slash before the path of the requested file :

    <img src = "/fiirst_folder/second_folder/third_folder/image.jpg" />

    Then it matters naught where the webpage is served from on that website.

    You need to read up on the difference between relative and absolute path.

    ps

    ../ means go up one directory from where I am now.

    ../images means go up one directory from where I am now, then go down into a directory called images

    These are relative links (relative to where I am now)
    Hi cups, Thank you for enlighten my mind...it helps me.

  10. #10
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    Hi @jemz,

    I have struggled with paths and now define all paths in a constant.php. The file is then included:

    # constants.php
    PHP Code:

    # constants
    define('LOCALHOST'in_array($_SERVER['SERVER_NAME'], array('localhost''127.0.0.1') ));

    if(
    LOCALHOST)
    {
      
    $tmp =  "c:\wamp\www\first_folder\second_folder\third_folder\";
      define('THUMB_PATH', substr(
    $tmp,2) );

      define('THUMB_URL', "
    http://subdomain.localhost/thumb/");
    }
    else
    {
      
    define('THUMB_PATH'"/home/content/42/558877/html/ci_john/subdomain/thumb/');" );

      
    define('THUMB_URL'"http://subdomain.Johns-Jokes.com/thumb/");

    #usage: - works both for LOCALHOST and Online
    PHP Code:

      
    require_once 'constants';   

      echo 
    "<img src='" .THUMB_URL  ."image.jpg'  style='border:0' alt='whatever' />"

  11. #11
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    Hi @jemz,

    I have struggled with paths and now define all paths in a constant.php. The file is then included:

    # constants.php
    PHP Code:

    # constants
    define('LOCALHOST'in_array($_SERVER['SERVER_NAME'], array('localhost''127.0.0.1') ));

    if(
    LOCALHOST)
    {
      
    $tmp =  "c:\wamp\www\first_folder\second_folder\third_folder\";
      define('THUMB_PATH', substr(
    $tmp,2) );

      define('THUMB_URL', "
    http://subdomain.localhost/thumb/");
    }
    else
    {
      
    define('THUMB_PATH'"/home/content/42/558877/html/ci_john/subdomain/thumb/');" );

      
    define('THUMB_URL'"http://subdomain.Johns-Jokes.com/thumb/");

    #usage: - works both for LOCALHOST and Online
    PHP Code:

      
    require_once 'constants';   

      echo 
    "<img src='" .THUMB_URL  ."image.jpg'  style='border:0' alt='whatever' />"
    Hi,Thank you so much for this,and for helping me...I give a try on this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •