将 .dat 文件读取为“rb”读取二进制文件
我在 webroot 上方有一个文件夹 \folder\
,其中包含 .php
、.inc
、.dat
文件
- < p>
.php
可以访问.inc
没问题 但是当
.inc
尝试使用fopen('mydat.dat', "rb"); 访问
.dat
时/code> 它给出了一个错误,它找不到mydat.dat
inside\folder\myinc.inc
当然它找不到它,因为.inc< /code> 是文件而不是文件夹。为什么 php 会这样对待它?
知道为什么 php 试图在 .inc
中查找 .dat
吗?
或 fopen($filename, "rb")
的任何其他替代方案?
I have a folder \folder\
above the webroot that contains .php
, .inc
, .dat
files
the
.php
can access the.inc
no problembut when the
.inc
tries to access the.dat
usingfopen('mydat.dat', "rb");
it gives an error that it can't findmydat.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")
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
阅读您的评论后,我认为您希望 fopen 使用 include_path。
fopen() 默认情况下不使用 include_path(与 include 不同)。这是一个选择。请参阅手册。
http://www.php.net/manual/en/function.fopen。 php
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
学习文件系统基础知识。
您的工作目录仍在 webroot 中。它不会将其更改为 \folder\ (尽管新版本的 PHP 似乎确实会在当前文件位置查找文件)。
无论如何,如果您想在同一目录中打开文件,
您可以使用 myinc.inc 中的
dirname(__FILE__)
始终适合您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 youin the myinc.inc you can use
听起来您有
safe_mode
已启用,但没有
open_basedir
,或者将文件放在其外部。将 .dat 文件放入该选项指定的路径中。Sounds like you have
safe_mode
enabled, but don't have a value foropen_basedir
, or have the file outside it. Put the .dat file in a path given to that option.当我们在 php.ini 中处理文件时。有必要给出路径+文件名以避免此类错误。
When ever we deal with files in php. It is necessary to give path+file name to avoid such type of errors.