2

I'm including PHP Class like that require_once(realpath($_SERVER["DOCUMENT_ROOT"]).'\xampp\htdocs\aclass\classfile.php');

but when i executed the code thow a error

Warning: require_once(C:\xampp\htdocs\xampp\htdocs\aclass\classfile.php): failed to open stream: No such file or directory in C:\xampp\htdocs\aclass\index.php on line 2
Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\xampp\htdocs\aclass\classfile.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\aclass\index.php on line 2

fileclass.php

    <?php  
class Test{
    public function hello(){
        echo "hello every one";
    }
}

testclass.php

<?php

require_once (realpath($_SERVER["DOCUMENT_ROOT"]).'\xampp\htdocs\aclass\classfile.php');
$var=new Test();
$var->hello();

thank you in advance!!

KAMAL96
  • 37
  • 1
  • 3
  • 8

2 Answers2

4

The DOCUMENT_ROOT is already in \xampp\htdocs, so you can skip that part:

require_once(realpath($_SERVER["DOCUMENT_ROOT"]).'\aclass\classfile.php');
Laurens
  • 2,596
  • 11
  • 21
0

if you are trying to shift site from server to local then it may also occur just check if your htacces file is in public copy that to the main root directory

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – ethry Aug 28 '22 at 04:49