1

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>
7
  • include 'admin/announcement2.php' Commented Aug 1, 2012 at 4:11
  • 1
    post your directories structure Commented Aug 1, 2012 at 5:48
  • change post title - the problem is not that the pages are user and admin, the problem is with php includes Commented Aug 1, 2012 at 5:49
  • What does echo getcwd() write? Commented Aug 1, 2012 at 6:01
  • are you able to open localhost/admin/announcement2.php?? or maybe it is localhost/pods/admin/announcement2.php Commented Aug 1, 2012 at 6:02

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

25 Comments

thanks for your concern, I've paste your short path coding into my coding, but It's still not solve the problem.
@neokio: it is a backtick (`), not a tilde (~). It's next to the 1 only on English keyboards.
something else worth mentioning, you've asked 5 questions but 'accepted' none. you are more likely to get good/fast answers on stackoverflow if you accept their answers (clicking the checkmark next to their answer) and upvote (clicking the up arrow). we programmers are quite vain :) many take it way too seriously. but really, reputation (peer review) is what makes stackoverflow work so well.
That probably wouldn't be very useful. I'd suggest you try this: 1) Make a php file named "test1.php" with only this in it: <?php include('test2.php'); ?> 2) Make a php file named "test2.php" with only this in it: <?php echo "Success!"; ?> 3) Load test1.php in a browser (localhost/test1.php) 4) If that succeeds, create a directory "test3", and move test2.php into it. Change test1.php to `<php include('test3\test2.php'); ?> and see if that works.
good work! 90% of debugging is figuring out where the bug is. it's important to check your assumptions at every step. good luck!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.