gmc1103 Posted January 13, 2016 Share Posted January 13, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/ Share on other sites More sharing options...
cyberRobot Posted January 13, 2016 Share Posted January 13, 2016 You could try DOCUMENT_ROOT? require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php"; Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529571 Share on other sites More sharing options...
gmc1103 Posted January 13, 2016 Author Share Posted January 13, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529579 Share on other sites More sharing options...
ginerjm Posted January 13, 2016 Share Posted January 13, 2016 In the error message does the path noted as the place where the doc is NOT found (and filename too!) agree with your own manual (ie, visual) inspection of your server's file system? Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529580 Share on other sites More sharing options...
cyberRobot Posted January 13, 2016 Share Posted January 13, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529583 Share on other sites More sharing options...
benanamen Posted January 13, 2016 Share Posted January 13, 2016 (edited) 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 January 13, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529584 Share on other sites More sharing options...
gmc1103 Posted January 13, 2016 Author Share Posted January 13, 2016 (edited) 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 January 13, 2016 by gmc1103 Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529591 Share on other sites More sharing options...
ginerjm Posted January 13, 2016 Share Posted January 13, 2016 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"? Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529594 Share on other sites More sharing options...
Solution mac_gyver Posted January 13, 2016 Solution Share Posted January 13, 2016 (edited) 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 January 13, 2016 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/300304-require_once-problem/#findComment-1529595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.