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
Old 04-07-2008, 10:01 PM   #1 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
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, 09:18 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
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, 09:34 AM   #3 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
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, 12:44 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
Quote:
failed to open stream: Permission denied
does the web user have permission to read this file?
__________________
Mike
sde is offline   Reply With Quote
Old 04-08-2008, 01:08 PM   #5 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
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, 01:15 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
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?
__________________
Mike
sde is offline   Reply With Quote
Old 04-08-2008, 01:37 PM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
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, 01:49 PM   #8 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
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, 02:45 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
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
__________________
Mike
sde is offline   Reply With Quote
Old 04-08-2008, 04:10 PM   #10 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
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, 01:03 PM   #11 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
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, 01:12 PM   #12 (permalink)
metazai
Regular Contributor
 
Join Date: Apr 2004
Location: Orange County, CA
Posts: 136
metazai is on a distinguished road
It's completely blank. No value. Null.
metazai is offline   Reply With Quote
Reply

Bookmarks

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

BB 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 01:22 PM
Random Internal Server Errors ZachH PHP 6 03-14-2005 12:29 PM
Suppressing errors with the cp command sde Linux / BSD / OS X 2 11-08-2004 11:15 AM
errors, .. hard drive related? sde Linux / BSD / OS X 1 07-31-2002 09:29 PM


All times are GMT -8. The time now is 09:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting