【问题标题】:Can't open .txt file with php Mac (Xampp)无法使用 php Mac (Xampp) 打开 .txt 文件
【发布时间】:2021-03-12 23:13:49
【问题描述】:

这是我的代码给我的错误消息:

警告:fopen(users.txt):打开流失败:第 79 行 /opt/lampp/htdocs/assignment3/form.php 中的权限被拒绝 无法打开文件。

这是我的代码:

$file = fopen("users.txt", "a") or die("Unable to open file.");

我刚开始用 mac 编码,所以我不太了解它。提前感谢您的帮助

【问题讨论】:

    标签: php macos fopen


    【解决方案1】:

    运行此代码轻松找到正确的文件夹

    <?php
    
    $txt = 'users.txt';
    
    echo '<br> your php file is here : ' . __FILE__;
    
    echo '<br> your text file should exists in : ' . __DIR__ . '/' . $txt;
    
    echo '<br> your text file '.( file_exists($txt)?'exists':'not exists' );
    
    echo '<br> your text file is '.( is_readable($txt)?'readable':'not readable' );
    
    echo '<br> your text file is '.( is_writable($txt)?'writable':'not writable' );
    
    echo '<br> your dir is '.(
            is_writable(__DIR__)?
                'writable, then you can create new files':
                'not writable, then you can not create any files'
        );
    

    Demo

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 2020-08-05
      • 2018-04-12
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      相关资源
      最近更新 更多