1
I need to make my file that makes the class instance of my project work on both the web server and the local server.
This is the file that makes autoload, autoload.php
<?php
spl_autoload_register ( function ($classe){
$classesDiretorio = __DIR__.'/classes/';
$classesArquivo = $classesDiretorio . ' / ' . $classe . '.php';
if(file_exists($classesArquivo)){
require_once ($classesArquivo)
}
});
In xampp, it works well, but when I go to the site, it gives error in the address of the path.
Follow the error:
Fatal error: Class 'Client' not found in /home/diego325/public_html/temporario/rental/cadastro.php on line 13
How can I get autoload to take the paths from both the local server and the web server?
I believe my problem is similar to that:
But in the problem mentioned above there was no solution.
There is a directory called
classes
in/temporario/rental/
, containing the fileCliente.php
?– Woss
Apparently there is nothing wrong. The code presented works well in diverse environments, except for the use of constant
__DIR__
because this is available from PHP5.3 http://php.net/manual/en/language.constants.predefined.php. If this is not the problem, check that the filenames are in agreement, with upper and lower case letters. The linux file system is case sensitive. If the file is php client., will give this error. It must be Php client. (I presume).– Daniel Omine
Opa Wanderson, yes. This is the one I use to instantiate the Client class.
– DiChrist
So Daniel, this is it DIR same that is giving the problem. In my case it is linux server same. The php version on the server is 5.6.30. I tried to make use of $_SERVER values, but I was unsuccessful.
– DiChrist
you can always try replacing the
__DIR__
fordirname(__FILE__)
and see if it solves the problem. You should also take into account the/
, which may vary at the server’s discretion, DIRECTORY_SEPARATOR ?– Edilson