将 .dat 文件读取为“rb”读取二进制文件

发布于 2024-08-27 20:23:44 字数 595 浏览 5 评论 0原文

我在 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 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")?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黑色毁心梦 2024-09-03 20:23:44

阅读您的评论后,我认为您希望 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

耳根太软 2024-09-03 20:23:44

学习文件系统基础知识。
您的工作目录仍在 webroot 中。它不会将其更改为 \folder\ (尽管新版本的 PHP 似乎确实会在当前文件位置查找文件)。

无论如何,如果您想在同一目录中打开文件,

您可以使用 myinc.inc 中的dirname(__FILE__) 始终适合您

fopen(dirname(__FILE__).'/mydat.dat', "rb");

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");
荆棘i 2024-09-03 20:23:44

听起来您有 safe_mode已启用,但没有 open_basedir,或者将文件放在其外部。将 .dat 文件放入该选项指定的路径中。

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.

〆凄凉。 2024-09-03 20:23:44

当我们在 php.ini 中处理文件时。有必要给出路径+文件名以避免此类错误。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文