Mohamed Athif Mohamed Athif - 2 years ago 129
PHP Question

including a PHP file from localhost gives warning

i have an index file with PHP code in localhost/KK/admin/pages

require_once 'url.php';
include 'localhost/KK/admin/pages/sidebar.php';

url.php is within the same folder as index.php file. sidebar.php is in localhost/KK/admin/pages/admin/pages.

url.php has the code

$url = "localhost/KK";

when i open index.php it gives me

Warning: include(localhost/KK/admin/pages/sidebar.php): failed to open
stream: No such file or directory in


Warning: include(): Failed opening
'localhost/KK/admin/pages/sidebar.php' for inclusion
(include_path='.;C:\php\pear') in

can anyone explain why i am getting these errors and why i cant call sidebar.php? also a possible solution?

Answer Source

Let's traverse your directory: localhost/KK/admin/pages/sidebar.php

Your script file is located here: C:\wamp64\www\KK\admin\pages\ or KK\admin\pages\

From KK\admin\pages\ you ask for a directory (thats right, a directory not your server) localhost, from localhost to KK to admin to pages.

include 'sidebar.php'; will do fine as the script is located in KK\admin\pages\ and your include as well so you can include the file relative to the location of index.php located in C:\wamp64\www\KK\admin\pages\

Instead use the relative path, ..\ to go back 1 directory or use a constant to keep track of your root.

  const ROOT = 'C:\wamp64\www\';
  include ROOT . 'folder\file.php';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download