PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Tue Oct 25, 2005 11:18 am
I am trying to log to files that are above the root directory... how come this won't work?
Code: Select all
function logerror($error){
$date = time();
$file = "../errors/errors.php";
if($fh = fopen($file, "a")){
$newerror = date("h:i:s Y/m/d", $date)."
Error: $error
Page: ".$_SERVER['PHP_SELF']."
";
fwrite($fh, $newerror);
fclose($fh);
}
}
ERROR:
Warning: fopen(../errors/errors.php): failed to open stream: No such file or directory in /home/pdirect/public_html/includes/functions.php on line 21
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Tue Oct 25, 2005 11:22 am
try hard coding the page location?
Maugrim_The_Reaper
DevNet Master
Posts: 2704 Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland
Post
by Maugrim_The_Reaper » Tue Oct 25, 2005 11:29 am
echo
realpath("../errors/errors.php");
to screen and ensure its matching your full path. Using realpath() itself might work - symbolic links can be a bit awkward on some systems.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Tue Oct 25, 2005 11:44 am
How do I find out the real path to that? when I echoed realpath("../errors/errors.php") I got nothing.
Maugrim_The_Reaper
DevNet Master
Posts: 2704 Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland
Post
by Maugrim_The_Reaper » Tue Oct 25, 2005 11:46 am
/home/pdirect/public_html/includes/functions.php
from the error message?
You shouldn't really post full paths to forums - just a little advice
But there's your answer in full view - test using the full path and it'll work for sure.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Tue Oct 25, 2005 11:52 am
I recommend getting the path by using
Code: Select all
dirname($_SERVER['DOCUMENT_ROOT']).'/includes/';
This way if you change your server you won't have to change the path in your code.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Oct 25, 2005 12:11 pm
The path he actually wants is:
/home/pdirect/public_html/errors/errors.php
Change your function to:
Code: Select all
function logerror($error){
$date = time();
$file = realpath("../errors/errors.php");
if($fh = fopen($file, "a")){
$newerror = date("h:i:s Y/m/d", $date)."
Error: $error
Page: ".$_SERVER['PHP_SELF']."
";
fwrite($fh, $newerror);
fclose($fh);
}
}
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Oct 28, 2005 2:01 pm
Code: Select all
dirname($_SERVER['DOCUMENT_ROOT']) did not work... and the new server I am working on is windows which I think makes things weird... look at the path in the error message:
Error wrote: e:\Inetpub\wwwroot\admin\news\index.php
I work with about 10 diff servers and this one is windows.
Last edited by
Luke on Fri Oct 28, 2005 2:08 pm, edited 1 time in total.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Oct 28, 2005 2:08 pm
Code: Select all
include(realpath("../functions.php"));
include(realpath("../classes.php"));
Did not work either:
Warning: main() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in e:\Inetpub\wwwroot\admin\news\index.php on line 2
Warning: main() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in e:\Inetpub\wwwroot\admin\news\index.php on line 3