[英]How to fix ‘No such file or directory’ error in PHP
I'm trying to run a php website on my localhost using xampp, but keep getting a 'No such file or directory' this is the warning i get:-我正在尝试使用 xampp 在我的本地主机上运行一个 php 网站,但不断收到“没有这样的文件或目录”,这是我得到的警告:-
Warning: require_once(D:/wamp/www/ntany3/system/startup.php): failed to open stream: No such file or directory in C:\xampp\htdocs\ntany3\index.php on line 17
警告:require_once(D:/wamp/www/ntany3/system/startup.php):无法打开流:第 17 行的 C:\xampp\htdocs\ntany3\index.php 中没有这样的文件或目录
Fatal error: require_once(): Failed opening required 'D:/wamp/www/ntany3/system/startup.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\ntany3\index.php on line 17
致命错误:require_once():在 C:\xampp\htdocs\ntany3\ 中打开所需的 'D:/wamp/www/ntany3/system/startup.php' (include_path='C:\xampp\php\PEAR') 失败第 17 行的 index.php
// Startup
require_once(DIR_SYSTEM . 'startup.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将以下代码放入一个新文件并将其命名为 path.php 然后将其上传到您的根目录并转到 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:打开你的
httpd.conf
(它是apache配置文件)并编辑它:
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...你的错误发生是因为你得到了错误的路径,这是因为你的 apache 配置中的
DocumentRoot
指向一个不存在的路径......
I suggest you to use full path... eg:我建议您使用完整路径...例如:
require_once($_SERVER['DOCUMENT_ROOT'] . "/ntany3/system/startup.php");
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.