如何修复 PHP 中的“没有这样的文件或目录”错误

我正在尝试使用 xampp 在我的本地主机上运行一个 php 网站,但不断收到“没有这样的文件或目录”,这是我得到的警告:-

警告:require_once(D:/wamp/www/ntany3/system/startup.php): 无法打开流:C:xampphtdocsntany3index.php 第 17 行没有这样的文件或目录

致命错误:require_once():在第 17 行的 C:xampphtdocsntany3index.php 中打开所需的 'D:/wamp/www/ntany3/system/startup.php' (include_path='C:xamppphpPEAR') 失败

// Startup
require_once(DIR_SYSTEM . 'startup.php');
stack overflow How to fix ‘No such file or directory’ error in PHP
原文答案

答案:

作者头像

I think you could add the path relative to current directory, like this:

require_once(__DIR__. '/system/startup.php');

Put below code in a new file and name it path.php Then upload it to your root directory and go www.example.com.com/path.php

and it'll tell you the full path.

$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";

Take that path and edit both config files .

作者头像

Open your httpd.conf (it's apache config file) and edit it:

Where you have:

DocumentRoot "C:/xampp/htdocs"

Change to:

DocumentRoot "D:/wamp/www"

Your errors happen because you are getting the wrong path, this happens because your DocumentRoot in your apache config is pointing to an non-existent path...

I suggest you to use full path... eg:

require_once($_SERVER['DOCUMENT_ROOT'] . "/ntany3/system/startup.php");

Hope this helps.

相关问题