2

I have the following folder structure with files:

index.php
includes/header.php
includes/conn.php
contents/ad_list.php
contents/ad_posting.php

in my index.php I have the following include

include("includes/header.php"); its ok

but in contents/ad_list.php the above include give the following error:

Warning: include(includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\XAMPP\xampp\htdocs\NAYAAD\contents\ad_list.php on line 4

I couldn't solve this problem.

Regards:

4 Answers 4

1

You will need to go up one level:

include("../includes/header.php");
Sign up to request clarification or add additional context in comments.

5 Comments

thanks dear Mike GB, my includes/header.php has link to includes/conn.php and on every page I include includes/header.php so it displays my header and includes/conn.php connect to database. now on 1st include("../includes/header.php"); in my index.php solve the problem but from index.php when I click on link to contents/ad_list.php it don't find the includes/header.php and also includes/conn.php.
Have you tried including it as the file only (since both files are in the same directory)? include('conn.php'); inside header.php
good. its okey. but the others files and different folders have problems.
Now I am unable to link my css style, '<link type="text/css" rel="stylesheet" href="includes/style.css" />' the includes/header.php is link to this file and both are in the same folder.
Does '<link type="text/css" rel="stylesheet" href="style.css" />' work?
1

In this case, include("../includes/header.php"); solve the problem, but, the best way is known root of your application and use it for base for includes.

You need to set include_path in your php.ini relative to your application root folder, or, try with $_SERVER['DOCUMENT_ROOT'];

1 Comment

by using $_SERVER['DOCUMENT_ROOT']; its now ok, but I have to specify full path for files.
0

Try including dirname on your inclusion.

<?php
include dirname(__FILE__)."/../contents/ad_list.php";
?>

the dirname(_FILE) can make it more portable and depending on where its running, you could just copy it up and add dots as needed.

1 Comment

If you need to use your php via cronjob or via commandline, the dirname() is sometimes needed.
0

try put a "." infrontof the address

include("./contents/ad_list.php");

2 Comments

Firstly you're trying to include the wrong file, and second of all the "." means "from the same directory". You need ".." to go up one level.
this soloved my problem: ' include($_SERVER["DOCUMENT_ROOT"]."/includes/conn.php");'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.