Why when I upload my page made with php I get an error in linux and in windows if it loads correctly?

1

I have a problem, and I have not found the solution. What happens is that I charge my project in xamp, htdocs, in windows and I open the page and all without any inconvenience. But when doing the same in linux I see this error on the web.

Warning: require_once (/inicio.php): failed to open stream: The file or directory does not exist in /opt/lampp/htdocs/festivalvallenato/index.php on line 12

Fatal error: require_once (): Failed opening required '/inicio.php' (include_path = '.: / opt / lampp / lib / php') in /opt/lampp/htdocs/festivalvallenato/index.php on line 12

In linux I also use the xamp, and I keep the same windows project in linux but I do not know why it generates the error.

This is my index.php, I appreciate your help. Thanks.

// Pequeña lógica para capturar la pagina que queremos abrir
$pagina = isset($_GET['p']) ? strtolower($_GET['p']) : 'inicio';


// El fragmento de html que contiene la cabecera de nuestra web
require_once 'header.php';


/* Estamos considerando que el parámetro enviando tiene el mismo nombre del archivo a cargar, si este no fuera así
se produciría un error de archivo no encontrado */
require_once '/' . $pagina. '.php';

// Otra opción es validar usando un switch, de esta manera para el valor esperado le indicamos que página cargar


// El fragmento de html que contiene el pie de página de nuestra web
require_once 'footer.php';
    
asked by César Maiguel 13.05.2017 в 06:47
source

1 answer

1

You have the error in:

require_once '/' . $pagina. '.php';

If you put an / in the beginning in Linux you refer to an absolute path, therefore you are saying that your file is in /inicio.php.

You can delete the initial /, or put a point before because ./ refers to the current directory

These two forms should work for you

require_once './' . $pagina. '.php';
require_once $pagina. '.php';'
    
answered by 13.05.2017 в 14:56