Php: trouble "including" files


First-time poster–will try to be fully informative. Because I’m a nonexpert, I’ll probably overexplain some obvious things in an effort to be clear.

I am running an online research study using a set of php scripts (index file with conditional statements that load a whole series of php pages). Because there are many pages in different categories, I have them in separate subdirectories. For example, the parent directory is called “Seg” and the subdirectories include “Audio,” “Visual,” “Images,” and “Sound.”

The index file, in Seg, will load a page (C1B.php) from Audio, which should pull a header and a data-managing file from Seg, as well as an image from Images and sound files from Sound. Within C1B.php, I use relative file references, so–

<?php include '../header.php'; ?>


If I test a single page from the Audio directory by typing its full address directly into the browser address line, everything loads with no problem. However, when I try to run the program using the index file, then the invocation of the same page produces error messages:

Warning: main(…/header.php) [function.main]: failed to open stream: No such file or directory in /home/.napoli/name/ on line 2

Warning: main() [function.include]: Failed opening ‘…/header.php’ for inclusion (include_path=’.:/usr/local/lib/php’) in /home/.napoli/name/ on line 2

Can anyone help me understand why this happens so I can figure out how to fix it? I would really prefer NOT to go to absolute paths if possible. Thank you!!


Is that file (header.php) back one directory or is it in the same directory as index.php?

If it’s in the same directory then change the …/header.php to ./header.php

That error is saying it can’t find that file. Try an absolute path to header.php to test it.


Thanks a bunch.

In fact, it even works with just ‘header.php’ and no leading .s or /s. I forgot that the relative references need to be read by the index file and not the local file.

Thanks for your help. Fixed!!