【问题标题】:fopen() works, dio_open() doesn't?fopen() 有效, dio_open() 无效?
【发布时间】:2015-05-12 22:55:37
【问题描述】:

dio_open() 工作正常时,看到一些运行fopen() 的问题。这是我编写的一个测试脚本,用于检查问题,因为它出现在我正在尝试开始工作的新安装中。

<?php
        echo "Current User: " . get_current_user() . "<br/>";
        echo "UID: " . getmyuid() . "<br/>";
        echo "GID: " . getmygid() . "<br/>";
        echo "<br/>";
        $foTest = fopen("test.txt","r");
        echo fread($foTest,4);

        $fd = dio_open('test.txt', O_RDONLY);
        $read = dio_read($fd);
        echo $read;
        $file = dio_open('test.txt', O_WRONLY | O_CREAT);
?>

脚本输出以下内容:

当前用户:infinitywhack UID:1004 GID:1002

test 警告:dio_open(): 无法打开带有标志 0 的文件 test.txt 和 权限 0:没有这样的文件或目录 /var/www/infinity.whacknet.com/public_html/test.php 第 9 行

警告:dio_read() 期望参数 1 是资源,给定的布尔值 在 /var/www/infinity.whacknet.com/public_html/test.php 第 10 行

警告:dio_open(): 无法打开带有标志 65 和 权限 0:权限被拒绝 /var/www/infinity.whacknet.com/public_html/test.php 在第 12 行

这显示了正确的用户和组 (infinitywhack:www)。这里的“test”输出是 test.txt 文件的内容,也就是使用 fopen() 运行的代码。错误仅由 dio 函数给出。

以下是两个文件的权限:

[root@death public_html]# ls -la test.*
-r-xr-xr-x. 1 infinitywhack www 342 May 12 23:36 test.php
-rwxrwxrwx. 1 infinitywhack www   5 May 12 23:06 test.txt

我整晚都在摸索这个问题,关于我发现的任何 dio 的文档都很少。很少说这里需要什么。我唯一能想到的是 suExec,但没有使用任何指令会导致这种情况,尽管如果是这种情况,这些相同的指令对于 fopen 肯定也会失败?

这里的任何帮助将不胜感激!

【问题讨论】:

  • 是否有可能 dio_open 不读取相对路径?如果您尝试使用完全限定的路径会发生什么?

标签: php file fopen


【解决方案1】:

我认为 STLMikey 和 Ahmet 走在正确的轨道上。

试试dio_open(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt', ...)

至少在这个source code 中,dio_open 没有尝试构造绝对路径。 filename 参数不变地传递给操作系统。

No such file or directory & Permission denied 错误来自操作系统,而不是 dio 库。因此,您的服务器似乎在错误的位置寻找 test.txt

【讨论】:

  • 嘎!我不敢相信我没想到!原来是这样! dio 试图读取文件 /test.txt 而不是 /test.txt。我通过在脚本上完整设置引用文件来测试这一点,然后正确读取文件并输出内容。
【解决方案2】:

首先确保您的文件存在。 此外,您的 php 文件权限应为 0777 以创建文件 并且您可以通过此命令自动添加文件夹以设置权限“777”

$folder=mkdir( "yourdirname", 0777);

你应该试着去理解这个问题

 $file="test.txt";
    //maybe your server cannot find the root
    // if it does not solve the problem write root file command
// $file=dirname(__FILE__).DIRECTORY_SEPARATOR."test.txt";
    if (file_exists($file)) {
       //its ok try to continue
    } else {
        echo "the text file is not exits !";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多