views:

224

answers:

3

I have a folder \folder\ above the webroot that contains .php, .inc, .dat files

  • the .php can access the .inc no problem

  • but when the .inc tries to access the .dat using fopen('mydat.dat', "rb"); it gives an error that it can't find mydat.dat inside \folder\myinc.inc

Of course it can't find it since .inc is a file not a folder. Why is php treating it as such?

Any ideas why php is trying to find the .dat inside the .inc?

or any other alternatives to fopen($filename, "rb")?

A: 

Sounds like you have safe_mode enabled, but don't have a value for open_basedir, or have the file outside it. Put the .dat file in a path given to that option.

Ignacio Vazquez-Abrams
From the documentation I linked to: "This directive is ***NOT*** affected by whether Safe Mode is turned On or Off." Please check `open_basedir` as well.
Ignacio Vazquez-Abrams
So are you saying that `open_basedir` isn't present at all?
Ignacio Vazquez-Abrams
safe mode sounds like safe mode. It has these words, `safe mode` in the error message. Go figure.
Col. Shrapnel
+1  A: 

Learn filesystem basics. your working directory is still in the webroot. it doesnt change it to the \folder\ (although it seems new versions of PHP do look files within current file location).

Anyway if you want to open a file in the same directory, dirname(__FILE__) is always for you

in the myinc.inc you can use

fopen(dirname(__FILE__).'/mydat.dat', "rb");
Col. Shrapnel
@donpal why don't you try my code instead of empty argue? And what's the issue with .htaccess? your working directory is out of .htaccess reach
Col. Shrapnel
+1  A: 

After reading your comments, I think you expect fopen to use the include_path.

fopen() doesn't use the include_path by default(unlike include). It's an option. See the manual. http://www.php.net/manual/en/function.fopen.php

chris