T
T
tema219782020-09-22 19:19:42
PHP
tema21978, 2020-09-22 19:19:42

Why can't find the directory on the web hosting, but everything works on the local server (Open Server)?

I get error 500. Here are the logs:
[warn] [pid 20994] sapi_apache2.c(362): PHP Warning: require(/home/c/cs27399/public_html\\config\\routes.php): failed to open stream: No such file or directory in /home/c/cs27399/public_html/core/Router.php on line 10
[error] [pid 20994] sapi_apache2.c(362): PHP Fatal error: require(): Failed opening required '/home /c/cs27399/public_html\\config\\routes.php' (include_path='.:/opt/php71/share/pear') in /home/c/cs27399/public_html/core/Router.php on line 10

I I use the constant define('ROOT', dirname(__FILE__));
routes.php file

return [
  'api/auth/signin' => [
    'controller' => 'user',
    'action' => 'signin'
  ]
];

Router.php
class Router
{
    protected $routes = [];
    protected $params = [];
    public function __construct()
    {
        $this->routes = require ROOT . '\config\routes.php';
    }
    private function getURI()
    {
        if (!empty($_SERVER['REQUEST_URI'])) {
            return trim($_SERVER['REDIRECT_URL'], '/');
        }
    }
    


    public function match($uri)
    {
        $routeURI = preg_replace('/\d{1,}/','\d',$uri);
        if(isset($this->routes[$routeURI])){
            $this->params = $this->routes[$routeURI];
            return true;
        };
        
        return false;
    }

    public function run()
    {
        $uri = $this->getURI();
        if ($this->match($uri)) {
            $controllerFileName = ucfirst($this->params['controller']);
            $controllerFile = ROOT . '\\controllers\\' . $controllerFileName  . '.php';
            if (is_file($controllerFile)) {
                require_once $controllerFile;
                $classNameController = $controllerFileName.'Controller';
                $controller = new $classNameController($this->params); //Отправляем данные из routing в контроллер и создаем обьект с controller'ом
                $actionName = $this->params['action'].'Action';
                $controller->$actionName();
            }
        } else {
          
         require_once ROOT .'\\index.html';
        //   $controller = new ErrorController(['controller' => 'error']);
        //   $actionName = 'error404Action';
        //   $controller->$actionName();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-09-22
@tema21978

The hosting is most likely Linux, and the local OpenServer is on Windows. I vnguyu that the slash in the wrong direction. This is hinted at by the path in the error log.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question