Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Executing a php file from other location other than htdocs.

    Hi,
    I've a php file which needs to be executed which is placed in other location, other than htdocs folder. How do i do this? I've a index.html file from which i've to give link to php file.As a work around i've placed a shortcut to htdocs in the current directory where index.html file resides and I've given this as follows:

    Code:
    <u><a href="htdocs.lnk/weather.php">WEATHER FORECAST</u><BR>
    But it doesn't work ! Browser gives an error as file not found!
    or if i give the direct path as below :

    Code:
    <u><a href="C:\Program Files\Apache Group\Apache2\htdocs\weather.php"">BANGALORE WEATHER FORECAST</u><BR>
    It gives a pop up box saying Firefox doesn't know how to open this address,because the protocol isn't associated with any program.
    Please help me.

    Thanks,
    Ramki.
    Last edited by ramki067; 07-18-2008 at 05:49 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The protocol is http otherwise it needs to be file:. You cannot execute files outside of a published directory, but you can include files outside of you're directory into a published file.
    htdocs.lnk is likely an invalid directory. Sounds like you are doing this on you're local system, so to access the files you need to go to [127.0.0.1|localhost]/path/from/docroot/to/you're/file.php.
    To include external location files, use the include/require call:
    C:\
    - htdocs\
    index.php
    - external.php
    PHP Code:
    <?php
    require_once '../external.php';
    // or
    require_once 'C:\external.php';
    for example. So long as the directory and files are readable by apache (which in windows it will be) you can include the out of published directory file into any published file.
    That really the only way to do it - you cannot directly access one of these files from a webbrowser.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Though this is for XAMPP its the same general idea. You more than likely be editing the httpd.conf file.

    http://www.codingforums.com/showthread.php?t=142909
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Sep 2007
    Location
    Hanoi, Vietnam
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can:
    Code:
    include ("remote file");
    Use eval() to run the script after read (for simple scripts). Note you must rename the file != .PHP and put an eye to the security issue (permission settings)
    Code:
    $code = file_get_contents("remotefile");
    eval($code);
    ...


  •  

    Posting Permissions

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