【问题标题】:Windows 10 and PHP a file_get_contents() responds with permission deniedWindows 10 和 PHP 的 file_get_contents() 响应权限被拒绝
【发布时间】:2020-02-10 05:29:52
【问题描述】:

错误:

Warning: file_get_contents(C:\Users\ET\projects\results.php): failed to open stream: Permission denied in C:\Users\ET\projects\results.php on line 16

  • 第 16 行: $fileContents = file_get_contents("Files/$file","r");

  • XAMPP 与 PHP 7.3

  • IntelliJ PHPStorm 2019.2.3

  • Windows 10 家庭版

这在 IntelliJ IDE 的终端、CMD 和以管理员身份打开的 CMD 中都失败了。

在没有chmod 的窗口中如何解决这个问题?

【问题讨论】:

    标签: php windows xampp


    【解决方案1】:

    将您的项目文件复制到(它是 xampp 文档文件夹:c:/xampp/htdocs for (php,html,css,js)):

    c:/xampp/htdocs/proj1
    c:/xampp/htdocs/proj2
    

    然后设置虚拟主机:C:\xampp\apache\conf\extra\httpd-vhosts.conf

    <VirtualHost *:80>
    DocumentRoot "c:/xampp/htdocs/proj1"
    ServerName proj1.xx
    ServerAlias www.proj1.xx
    <Directory "c:/xampp/htdocs/proj1">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot "c:/xampp/htdocs/proj2"
    ServerName proj2.xx
    ServerAlias www.proj2.xx
    <Directory "c:/xampp/htdocs/proj2">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
    </VirtualHost>
    

    在 windows hosts 文件中创建:C:\Windows\System32\drivers\etc

    127.0.0.1 localhost proj1.xx proj2.xx
    

    重启xampp apache2,浏览器然后在浏览器中运行:

    http://proj1.xx

    或者

    http://proj2.xx

    您当然可以在 xampp virtualhosts 文件中将 c:/xampp/htdocs/proj1 更改为您的项目路径 C:\Users\ET\projects

    附:您不了解基础知识...阅读和学习。

    【讨论】:

    • 感谢您投入时间并让我知道我不了解基础知识,但这与 apache 无关,而是与 PHP 和用户/应用程序/权限有关,请再次阅读问题。
    猜你喜欢
    • 2022-07-21
    • 2019-03-25
    • 2016-03-26
    • 2012-04-26
    • 2018-07-23
    • 1970-01-01
    • 2018-07-28
    • 2018-11-20
    • 2017-04-01
    相关资源
    最近更新 更多