You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在XAMPP运行公司网站副本时遇文件找不到错误求助

Fixing the "Failed to Open Stream" Path Error in XAMPP

Hey there! That error is super common when moving code from a Linux server to a Windows XAMPP setup—let's sort it out quickly.

What's causing this?

The error is pointing to a Linux-style absolute path: /var/www/html/classes/database_class_pdo.php. That's the path your company's live server uses, but on your Windows machine, XAMPP stores files in D:\xampp\htdocs\HJ\ instead. The system can't find a folder called /var/www/html/ on your Windows drive, hence the "no such file or directory" warning.

How to fix it

Here are two reliable solutions:

  • Use relative paths instead of absolute paths
    Open top.php and look at line 10. Replace the absolute path with a path relative to where top.php is stored. For example:

    • If the classes folder is inside your HJ directory (so D:\xampp\htdocs\HJ\classes\database_class_pdo.php), change the line to:
      require_once('classes/database_class_pdo.php');
      
    • If the classes folder is one level up from HJ (in htdocs directly), use:
      require_once('../classes/database_class_pdo.php');
      
  • Define a root path constant (more scalable)
    This is a better long-term fix, especially if you have multiple files with hardcoded paths. Add this line at the very top of top.php (before the require_once line):

    define('ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
    

    Then update the require_once line to use this constant:

    require_once(ROOT_DIR . 'classes/database_class_pdo.php');
    

    dirname(__FILE__) gets the full path to the folder where top.php lives, and DIRECTORY_SEPARATOR automatically uses / or \ depending on your OS, so it works on both Linux and Windows.

Quick double-check

Make sure the file database_class_pdo.php actually exists in the classes folder you're targeting. It's easy to accidentally misplace files when copying a site!

内容的提问来源于stack exchange,提问作者Arshadh Haroon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:40:45