Failed to open stream: No such file or directory in. Localhost x Locaweb [closed]

-2

I made an application on my machine using the Wampserver server. However, uploading this application to Locaweb generates the following error. The PHP version of Locaweb is 7.1.

  Warning: include_once (/include/head.php): failed to open stream: No such file or directory in /home/storage/3/46/ab/meusite/public_html/dashboard.php on line 25

    
asked by anonymous 09.09.2018 / 18:27

1 answer

1

Fábio, the server does not mind, so if it says there is no file, then probably this file does not exist.

The index of your application is probably located in the following folder on the Locaweb server:

/home/storage/3/46/ab/meusite/public_html/index.php

Then when doing the include this way:

<?php
include_once('/include/head.php')
?>

The server will look for an include folder at the root of the server and not at the root of the application:

/include/head.php

You can include the head.php using the magic constant __ DIR__ or the getcwd , which will return the basic directory of the file being executed, or DOCUMENT_ROOT (when present), which also points to the root of the application.

+ - so no index.php :

<?php
include_once(getcwd() . '/include/head.php');

include_once(__DIR__ . '/include/head.php');

include_once($_SERVER['DOCUMENT_ROOT'] . 'include/head.php');
?>

A good practice is to define a constant with the base directory of your application and then use it whenever you want to do an include.

index.php

<?php
define('APP_PATH', getcwd());

include_once(APP_PATH . '/include/head.php');
?>

I hope I have helped.

    
10.09.2018 / 02:21