Jump to content

require_once problem


gmc1103
Go to solution Solved by mac_gyver,

Recommended Posts

Hi 

 

I'm having a problem regarding this function

 

I have a folder (admin_pages) who have inside a file, that file should call another file inside a root folder

 

i have tried 

require_once("../include/membersite_config.php");

And it gives me error

Warning: require_once(./include/fg_membersite.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/include/membersite_config.php on line 2

This is my structure

 

any help to get into include folder from admin_pages file folder?

 

Thanks

post-174418-0-44460800-1452687572_thumb.png

Link to comment
Share on other sites

No...it gives me that error

Warning: require_once(/home/ebspma/public_html../include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4

 

Does your code look like this

require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php";

Or this

require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php";
 
Note that the ".." isn't needed when you're already in the document root and your accessing a folder in the document root.
Link to comment
Share on other sites

Where you are requiring the fg_member site you need two dots instead of one. It is doing that because you are requiring an include from a subfolder of root that includes an include. I usually put my config file in the root directory and then include the include files to that main config file. Then you just need to include the config from root as needed.

Edited by benanamen
Link to comment
Share on other sites

Hi again

 

With this code

require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php";

i have this error

Warning: require_once(/home/ebspma/public_html/include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4

Wtis this code

require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php";

I have this error too

Warning: require_once(/home/ebspma/public_html../include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4

So, i think there is somthing wrong

 

This is my code

<?PHP
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php";
if (!$ebspma->CheckLogin()) {
    $ebspma->RedirectToURL("index.php");
    exit;
}
include '../menus/menus.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>EBSPMA - Gráfico</title>
        <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
        <link href="../css/bootstrap-table.css" rel="stylesheet" type="text/css"/>
        <link href="../css/bootstrap-editable.css" rel="stylesheet" type="text/css"/>
        <link rel="stylesheet" href="../css/formValidation.min.css">
    </head>
    <body>
        <div class="row">
            <div class="col-md-12">
                <div class="row clearfix">
                    <div class="col-md-12 column">
                        <div class="alert alert-info"><h3>Atividades por meses</h3></div>
                    </div>
                </div>
                <div class="col-md-2"></div>
                <div class="col-md-8" id="visualization" style="width: 800px; height: 400px;"></div>
                <div class="col-md-2"></div>
                <?php
                include 'mysqliconn.php';
                $query = "SELECT idativade, DATE_FORMAT(data, '%b') AS Datas, COUNT( * ) AS Atividades FROM `ebspma_paad_ebspma`.`nem_pae_atividades` GROUP BY Datas ORDER BY data";
                $result = $mysqli->query($query);
                $num_results = $result->num_rows;
                if ($num_results > 0) {
                    ?>
                    <script type="text/javascript" src="http://www.google.com/jsapi"></script>  
                    <script type="text/javascript">
                        google.load('visualization', '1', {'packages': ['corechart', 'geochart', 'table']});
                    </script>
                    <script type="text/javascript">
                        function drawVisualization() {
                            // Create and populate the data table.
                            var data = google.visualization.arrayToDataTable([
                                ['Datas', 'Atividades'],
            <?php
            while ($row = $result->fetch_assoc()) {
                extract($row);
                echo "['{$Datas}', {$Atividades}],";
            }
            ?>
                            ]);
                            new google.visualization.ColumnChart(document.getElementById('visualization')).
                                    draw(data, {title: "Distribuição Mensal"});
                        }
                        google.setOnLoadCallback(drawVisualization);
                    </script>
                    <?php
                } else {
                    echo "Sem atividades registadas";
                }
                ?>  
            </div>
        </div>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="../js/formValidation.min.js"></script>
        <script src="../js/bootstrap.min.js"></script>
        <script src="../js/bootstrap.min2.js"></script>
        <script src="../js/bootstrap-table.js"></script>
        <script src="../js/bootstrap-table-export.js"></script>
        <script src="../js/bootstrap-table-pt-PT.js"></script>
        <script type="text/javascript" src="../js/tableExport.js"></script>
        <script type="text/javascript" src="../js/jquery.base64.js"></script>
        <script type="text/javascript" src="../js/sprintf.js"></script>
        <script type="text/javascript" src="../js/jspdf.js"></script>
        <script type="text/javascript" src="../js/base64.js"></script>
    </body>
</html>
Edited by gmc1103
Link to comment
Share on other sites

The use of the .. is completely wrong. Just look at the path in the error message that you get - doesn't it look wrong to you?

 

Secondly - are you sure that there is a file named "membersite_config.php" in the folder: "/home/ebspma/public_html/include"?

Link to comment
Share on other sites

  • Solution

your error message has changed, because the problem changed.

 

the original error was due to fg_membersite.php, not membersite_config.php. in the first post, the require_once() for membersite_config.php was working. it was the require_once() for fg_membersite.php, inside of membersite_config.php, that wasn't working.

 

the most immediate problem is now the path for membersite_config.php.

 

all the folders in question are inside a folder named gesdocente.

 

you either need to add the gesdocente folder to the absolute path you are making for all the require_once() statements OR you need to make the relative path using two .. for all the require_once() statements.

 

edit: relative paths, anything that starts with a ./ or ../ are relative to the main file that was requested, because when you include/require code into your main file, its scope when it runs is the main file, not where it is stored at on the server.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.