View Full Version : Executing a php file from other location other than htdocs.

07-18-2008, 04:35 AM
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:

<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 :

<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.


07-18-2008, 05:12 AM
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 [|localhost]/path/from/docroot/to/you're/file.php.
To include external location files, use the include/require call:
- htdocs\
- external.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.

07-18-2008, 05:42 AM
Though this is for XAMPP its the same general idea. You more than likely be editing the httpd.conf file.


07-18-2008, 08:36 AM
You can:

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 = file_get_contents("remotefile");