Hi,

I created a log file log_php.txt to store some things that happens in my PHP code used by Apache.

.I use it like this

$strmsg = "An error appeared here.";
$file = "c:\logs_php.txt";
error_log($strmsg, 3, $file);

and sometimes but not always this error appears. You may noticed that i use Windows for development.

Warning: error_log(c:\logs_php.txt) [function.error-log]: failed to open stream: Permission denied in C:\work\La\trunk\php\htdocs\aaa\util_functions.php on line 40

Can you give me an explanation what might cause this to happen?

Chris

Hi,

I believe Windows is blocking the script from writing on C drive. Possible reason is that the location where the script is trying to write the file is outside of its working space, and the script do not have permission to do so.

Try changing the target location for logs_php.txt , it should be anywhere between htdocs and aaa directories. PHP script will not be able to write outside the htdocs directory. Outside this directory are write protected, and should be done by the root, but in windows there is no such definition unless you are physically writing the file . I mean DOS command can write in any space and any part of the physical drive, but not in php. PHP is more confined in the htdocs directory.

There a few exemption to this rule.. for example, if the php script is designed to execute a video encoder such as ffmpeg, mencoder, and metadata injectors such as flvtool2. Even though these applications are located in the root of the C drive, php exec function will still be able to execute these program without restriction. However, if we closely analyze what is really going on during the process, the output file is still saved and must be saved below the htdocs. All errors encountered by the ffmpeg during the process still have to be routed somewhere below the htdocs and not anywhere in the C drive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.