SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast luckyirish's Avatar
    Join Date
    Apr 2004
    Location
    New Jersey
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Absolute files paths

    Hey I just had a quick question: Is it possible to include and absolute file in a php page. For example, I tried the following very simple code:
    Code:
    <?php
    
    echo(C:\whatever directory\whatever the file is);
    
    ?>
    but it gives me the following error:

    Parse error: parse error, unexpected ':' in c:\program files\apache group\apache\htdocs\cookie.php on line 3

    is this even possible or am i wasting my time?
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.

    -Albert Einstein

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You wouldn't use echo to do it, since echo just prints a variable or string, it doesn't open files. If you open the file or include it or whatever you're doing, you'd have to escape those slashes, because it thinks you're trying to escape the letters after it... in other words c:\program files\apache.. becomes c:\\program files\\apache...

  3. #3
    SitePoint Enthusiast luckyirish's Avatar
    Join Date
    Apr 2004
    Location
    New Jersey
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what would the code look like
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.

    -Albert Einstein

  4. #4
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    //--  Use the include() function to include files

    //-- We have to use a \ infront of the \ so that PHP
    //-- knows to use a \ to seperate the path

    include("C:\\your_directory\\your_file.whatever"); 

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm not running a Windows server, but in Linux you'd do something like this:

    include("/home/user/www/file.php");

    If the file.php contents are enclosed in <? ?>, it'll include it as PHP code as if that code were right there where the include() is, otherwise it'll output its contents (useful for including menu HTML).

    In Windows I'd assume you could do similar:

    include("c:\\folder\\file.php");

  6. #6
    SitePoint Enthusiast luckyirish's Avatar
    Join Date
    Apr 2004
    Location
    New Jersey
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot guys - that really helped and i just learned something new
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.

    -Albert Einstein


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
  •