Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 04-07-2008, 09:01 PM   #1 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
fopen errors

Ok, I've built a CMS and installed same on several different servers. Occasionally I've had problems with the PHP code that writes to the created pages and files, but nearly always they've been permissions problems and once the fopen setting in php.ini. Now, however, I'm on a server that's thrown me another curve ball -- no matter what the permissions are on files, folders, or whatever -- even 777! -- I still get:
Code:
Warning: fopen(../../index.php) [function.fopen]: failed to open stream: Permission denied in /home/warriorg/public_html/admin/includes/publish.php on line 46 can't open ../../index.php
Incredibly frustrating . . . fopen is turned on in the .ini, and I'm at a loss of what to check next. Anybody with any thoughts? Remember this same code has worked literally on 10 other servers.
__________________
metazai is offline   Reply With Quote
Old 04-08-2008, 08:18 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
fopen( realpath( dirname(__FILE__).'/../../index.php' ) )
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 04-08-2008, 08:34 AM   #3 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
usage

Ok, so I've been using
Code:
$fh = fopen($myFile, 'w') or die("can't open ".$myFile);
. . . probably should have posted that to begin with. Not sure how this fits in with your code. I've tried a few iterations, but I'm a bit confused (which I often am, so it's a comfortable place).
__________________
metazai is offline   Reply With Quote
Old 04-08-2008, 11:44 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
Quote:
failed to open stream: Permission denied
does the web user have permission to read this file?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 04-08-2008, 12:08 PM   #5 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
permission?

How do you mean? It won't work even when all permissions are set to 777 -- which user are you referring to?
__________________
metazai is offline   Reply With Quote
Old 04-08-2008, 12:15 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
i'm talking about the apache user. if permissions are 777, and you still can't open it, then it must be something else.

have you tried it with another file? did it work before, then break?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 04-08-2008, 12:37 PM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
Did someone really try my answer?

If not you won't see the exact error.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 04-08-2008, 12:49 PM   #8 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
I couldn't interpret how your answer worked in place of the code I'd been putting, DJMaze . . . should I just replace _____FILE_____ AND index.php with my $myfile variable?
__________________
metazai is offline   Reply With Quote
Old 04-08-2008, 01:45 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,398
sde is on a distinguished road
i think __FILE__ is a constant for the current file. 2 underscores on each side.


edit: yeah here it is 'magic constant'

PHP: Magic constants - Manual
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 04-08-2008, 03:10 PM   #10 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
Cool . . . never heard of that one.

Regardless, now I don't get an error on fopen anymore with this (sorry DJMaze, I had to add in the 'w' or I got another error warning me it was missing):
Code:
$fh=fopen( realpath( dirname(__FILE__).$myFile),'w' );
But now, when I go to write the results to the file later after defining $bodysection and using
Code:
fwrite($fh, $headsection);
The result is that I get:
Code:
Warning: fwrite(): supplied argument is not a valid stream resource in /home/warriorg/public_html/admin/includes/publish.php on line 73
__________________
metazai is offline   Reply With Quote
Old 04-09-2008, 12:03 PM   #11 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 637
DJMaze is on a distinguished road
Can you check the output of
Code:
echo realpath( dirname(__FILE__).$myFile)
It seems that something is wrong with open_basedir or safemode.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 04-09-2008, 12:12 PM   #12 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 120
metazai is on a distinguished road
It's completely blank. No value. Null.
__________________
metazai is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile errors glennandrewcoop Standard C, C++ 3 04-17-2005 12:22 PM
Random Internal Server Errors ZachH PHP 6 03-14-2005 11:29 AM
Suppressing errors with the cp command sde Linux / BSD / OS X 2 11-08-2004 10:15 AM
pygtk errors schotty Python 4 02-20-2003 10:06 PM
errors, .. hard drive related? sde Linux / BSD / OS X 1 07-31-2002 08:29 PM


All times are GMT -8. The time now is 03:13 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle