开发者

Reading a .dat file as "rb" read binary

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 ins开发者_运维知识库ide the .inc?

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


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


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");


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.


When ever we deal with files in php. It is necessary to give path+file name to avoid such type of errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜