473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

using fopen() in write mode is failing

For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Jun 2 '08 #1
20 5068
On May 30, 9:08*pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
* * * * global $file;
* * * * if (file_exists($name) && file_exists($file)) {
* * * * * * * * if(($fp = fopen($file,"wb"))){
* * * * * * * * * * * * $lastmod = filemtime($name);
* * * * * * * * * * * * if(!(fwrite($fp, $lastmod))){
* * * * * * * * * * * * * * * * echo "cannot update time";
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * else{
* * * * * * * * * * * * echo "$file cannot be opened. \n";
* * * * * * * * }
* * * * }
* * * * else{
* * * * * * * * echo "$name or $file not found.";
* * * * }

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
Jun 2 '08 #2
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?

Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.

After turning on error reporting, it outputs this:

"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"

with line 53 being the $fp = fopen().. line.
Jun 2 '08 #3
cs******@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
>On May 30, 9:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.

I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.

After turning on error reporting, it outputs this:

"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"

with line 53 being the $fp = fopen().. line.
What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #4
On May 30, 4:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
cscor...@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.
After turning on error reporting, it outputs this:
"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"
with line 53 being the $fp = fopen().. line.

What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
The file named "time" is (sans quotations of course) in $file. The
time file itself is blank.

It was just set for rwx when I touched the file, so i just kept it and
added write permissions to the file for other users. I've changed it
to 0666 but it doesn't seem to affect anything.
Jun 2 '08 #5
On Sat, 31 May 2008 00:54:42 +0200, <cs******@gmail.comwrote:
On May 30, 4:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>cscor...@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as
the
>webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.
After turning on error reporting, it outputs this:
"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"
with line 53 being the $fp = fopen().. line.

What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

The file named "time" is (sans quotations of course) in $file. The
time file itself is blank.

It was just set for rwx when I touched the file, so i just kept it and
added write permissions to the file for other users. I've changed it
to 0666 but it doesn't seem to affect anything.
What is your getcwd()? Is it what you expect / the directory 'time' should
be in?
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #6
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
Jun 2 '08 #7
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

If you chmod $file to 0777 does your script then work?
Jun 2 '08 #8
On May 30, 6:02 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
What is your getcwd()? Is it what you expect / the directory 'time' should
be in?
--
Rik Wasmus
...spamrun finished
Yes, it returns the expected directory. Whenever I set the fopen to
use read mode, it gets into the if body fine.

On May 30, 9:59 pm, lawrence k <lkrub...@geocities.comwrote:
A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
Ah, I have a bad habit of that. I just write out what I think and
eventually get around to cleaning things up again once it works :]

On May 30, 10:17 pm, lawrence k <lkrub...@geocities.comwrote:
If you chmod $file to 0777 does your script then work?
No. All that does is add execute permissions to the file anyway.
Jun 2 '08 #9
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
Jun 2 '08 #10
cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

It's true. Is there any chance you've an older version of PHP installed,
some version from before the "b" flag was introduced? Have you tried:

fopen($file,"w")

just to see what would happen?
Jun 2 '08 #11
On May 31, 2:08 am, Lawrence Krubner <lawre...@krubner.comwrote:
cscor...@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

It's true. Is there any chance you've an older version of PHP installed,
some version from before the "b" flag was introduced? Have you tried:

fopen($file,"w")

just to see what would happen?
I've tried all modes that include writing options (r+, w+, a, etc),
and none of them seem to work. The PHP verion is 5.2.5, and reflects
that when I do phpinfo(). The server in question is Fedora9 with php/
apache installed via yum from the repos, and both have nearly default
settings.
Jun 2 '08 #12
On May 31, 3:59*am, lawrence k <lkrub...@geocities.comwrote:
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
* * * * global $file;
* * * * if (file_exists($name) && file_exists($file)) {
* * * * * * * * if(($fp = fopen($file,"wb"))){
* * * * * * * * * * * * $lastmod = filemtime($name);
* * * * * * * * * * * * if(!(fwrite($fp, $lastmod))){
* * * * * * * * * * * * * * * * echo "cannot update time";
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * else{
* * * * * * * * * * * * echo "$file cannot be opened. \n";
* * * * * * * * }
* * * * }
* * * * else{
* * * * * * * * echo "$name or $file not found.";
* * * * }
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?

A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
I personally find quite a few things some programmers designate as
"anti-patterns" are really just things the particular programmer
doesn't like. For example excessive commenting is claimed to be a
code smell, but I personally would much rather maintain a piece of
code with a lot of comments than a piece of code with none. It's true
enough that comments can be used incorrectly, for example using
esoteric variable names and using comments to say what they are,
variable names should be self-descriptive. And well written code will
get its what and how across quite well, but even the best written code
can't really convey its why. That's where comments come in.

As for the whole "Arrows anti pattern", the author asserts it results
in error handler code a long way from where the error might occur.
This is also true of exceptions, where the handler doesn't even have
to be in the same module. Overuse of exceptions is a far bigger sin
in my opinion than nesting ifs. The code and its error handler are
part of the same section in the arrow approach, and you can tell what
error handle belongs to what code because it will be on the same
indentation level.

Good code should narrative, which is more true of the arrow pattern
than badly used exceptions. There is nothing wrong with the structure
of the OP's code. In fact its structure pointed to exactly where the
problem lay almost immediately and allowed me to formulate a theory
quickly, namely that the script didn't have permission to write to the
file being manipulated.

As for the OP's problem, it looks from the error message PHP emitted
that the PHP user doesn't have write permission for the file in
question. I'd suggest adjusting chown, chmod and chgrp on the file,
but it looks like you've already done all that. Another possibility
is that some other program or script has opened and flocked the file
to prevent more than one process writing to it at a time. If the
software doesn't release its lock no other application or script can
write to it even if they do have permission. If other applications
have been accessing the file in question then try checking that they
have been closed down properly. If they have and the file is still
locked then you may have to resort to a restart of your system.
Jun 2 '08 #13
lawrence k wrote:
On May 30, 4:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?


If you chmod $file to 0777 does your script then work?
Why would you set the 'x' bit on a non-executable file? That's just
asking for even more trouble.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #14
cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
What OS is it running on (i.e. if Linux, which distro)? It could be the
OS security isn't allowing it, despite the file flags.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #15
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
cs******@gmail.com wrote:
>On May 30, 3:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be the
OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #16
Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>cs******@gmail.com wrote:
>>On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.

He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.
Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional security
features (like SE Linux), does it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #17
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
Rik Wasmus wrote:
>On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>>cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
>
PHP Version 5.2.5
Apache/2.2.8
>
code snip in question:
>
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
>
}
>
on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"
>
Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional security
features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC (Mandatory
Access Control) based security using ["SELinux"] enabled by default. "

So, now that you mention it, a chcon might be necessary...
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #18
Rik Wasmus wrote:
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>Rik Wasmus wrote:
>>On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:

cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
>file "time" is in the same directory as the .php file, with
>permissions set to 0766.
>>
>PHP Version 5.2.5
>Apache/2.2.8
>>
>code snip in question:
>>
>$file = "time";
>function updateParseTime($name){
> global $file;
> if (file_exists($name) && file_exists($file)) {
> if(($fp = fopen($file,"wb"))){
> $lastmod = filemtime($name);
> if(!(fwrite($fp, $lastmod))){
> echo "cannot update time";
> }
> }
> else{
> echo "$file cannot be opened. \n";
> }
> }
> else{
> echo "$name or $file not found.";
> }
>>
>}
>>
>on the 4th line it fails the if check ($fp = fopen..) and just
>outputs "$file cannot be opened"
>>
>Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time') ); output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?

Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "

So, now that you mention it, a chcon might be necessary...
Ah, OK. As I said I'm not familiar with it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #19
On Sat, 31 May 2008 15:55:26 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
Rik Wasmus wrote:
>On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>>Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:

cs******@gmail.com wrote:
>On May 30, 3:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode.
>>The
>>file "time" is in the same directory as the .php file, with
>>permissions set to 0766.
>>>
>>PHP Version 5.2.5
>>Apache/2.2.8
>>>
>>code snip in question:
>>>
>>$file = "time";
>>function updateParseTime($name){
>> global $file;
>> if (file_exists($name) && file_exists($file)) {
>> if(($fp = fopen($file,"wb"))){
>> $lastmod = filemtime($name);
>> if(!(fwrite($fp, $lastmod))){
>> echo "cannot update time";
>> }
>> }
>> else{
>> echo "$file cannot be opened. \n";
>> }
>> }
>> else{
>> echo "$name or $file not found.";
>> }
>>>
>>}
>>>
>>on the 4th line it fails the if check ($fp = fopen..) and just
>>outputs "$file cannot be opened"
>>>
>>Am I missing something?
> Actually, I think it must have something to do with the way this
>particular webserver is setup (be it apache/php), because it works
>fine when tested on another server (not maintained by me).
>
What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time')) ; output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "
So, now that you mention it, a chcon might be necessary...

Ah, OK. As I said I'm not familiar with it.
Haven't worked with SELinux either.. But it just might be the cause of all
this trouble.
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #20
On May 31, 9:07 am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Sat, 31 May 2008 15:55:26 +0200, Jerry Stuckle

<jstuck...@attglobal.netwrote:
Rik Wasmus wrote:
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<jstuck...@attglobal.netwrote:
>Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<jstuck...@attglobal.netwrote:
>>>cscor...@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode.
>The
>file "time" is in the same directory as the .php file, with
>permissions set to 0766.
>>>>>PHP Version 5.2.5
>Apache/2.2.8
>>>>>code snip in question:
>>>>>$file = "time";
>function updateParseTime($name){
> global $file;
> if (file_exists($name) && file_exists($file)) {
> if(($fp = fopen($file,"wb"))){
> $lastmod = filemtime($name);
> if(!(fwrite($fp, $lastmod))){
> echo "cannot update time";
> }
> }
> else{
> echo "$file cannot be opened. \n";
> }
> }
> else{
> echo "$name or $file not found.";
> }
>>>>>}
>>>>>on the 4th line it fails the if check ($fp = fopen..) and just
>outputs "$file cannot be opened"
>>>>>Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
>>>What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time') ); output.
>Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)
>I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "
So, now that you mention it, a chcon might be necessary...
Ah, OK. As I said I'm not familiar with it.

Haven't worked with SELinux either.. But it just might be the cause of all
this trouble.
--
Rik Wasmus
...spamrun finished
And it was. Disabled SELinux then rebooted, and now everything works
fine. I didn't even think of SELinux being a problem since I don't
recall being asked in setup/install if I wanted it enabled (which is
usually what happens)..

Thanks for the help all!
Jun 2 '08 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
10
by: Dave O'Hearn | last post by:
I want to open a file for both reading and writing, but when I do "ios::in|ios::out" with an fstream, it creates the file if it doesn't already exist. I don't like that last part. C's fopen has the...
9
by: monomaniac21 | last post by:
Hi everyone i'm trying to setup my website to create new webpages dynamically using php but I am have a major problem in that whenever i create a file it is always created locked so that it can...
10
by: Longfellow | last post by:
Newbie here... My reading of the description of fopen() led me to expect that, with mode as "w", it would create a file if it did not exist. Checked the FAQ and did not see this question...
7
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
1
by: msnews.microsoft.com | last post by:
Help! I'm working with a mixed mode project in which some existing code is calling fopen. ie., void SomeMethod(char* fileName) { FILE* filePointer; filePointer = fopen(fileName, "r");
0
by: filmo | last post by:
I've got a script that is receiving a PUT request from a Java Applet. To access the PUT data, the php script contains: $putdata = fopen("php://input","r"); error_log("PUTDATA = $putdata Last...
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
16
by: Hans Fredrik Nordhaug | last post by:
I'm trying to write to a file in the current directory - no remote files. The subject says it all - I can add that both the directory and the file is wordwritable. This happens on a (quite good)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.