mastersuse
mastersuse

Reputation: 988

PHP Include not working into my coding

I am running a website locally.

I have one main folder, which contains all main coding for normal users, it is a file named main.php.

Inside this main folder I have another folder for the admin, which contains, for example, the file named announcement2.php. However, when I try to include it in the front page (index.php), an error appears, it is like the server cannot read the file inside the admin folder.

The error is:

Warning: include(../admin/announcement2.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\pods\main.php on line 85

Warning: include() [function.include]: Failed opening '../admin/announcement2.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pods\main.php on line 85

And here is the code to include the file in the admin folder from main.php

<td><?php include '../admin/announcement2.php'; ?></td>

Upvotes: 1

Views: 780

Answers (1)

designosis
designosis

Reputation: 5263

This probably just means either (a) permissions are incorrect (web server can't read the file), or more likely, (b) the path is incorrect. If you echo $_SERVER['PHP_SELF']; you'll see the path of the script, which would shed light on what path to actually use. But it's usually faster to try a few variations ...

include '../admin/announcement2.php';
include 'admin/announcement2.php';
include '../../admin/announcement2.php';

... until something works.

Upvotes: 2

Related Questions