Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed opening '../tweets.php' for inclusion (include_path='.:')

Tags:

php

I am trying to include a script using the following code.

<div class="main_content">
    <?php include ('tweets.php')  ?>
</div>

But it keeps throwing up the following error.

Warning: include(tweets.php): failed to open stream: No such file or directory in - on line 52 Warning: include(): Failed opening 'tweets.php' for inclusion (include_path='.:') in - on line 52

I have checked and double checked and the file definitely exists and is in the same directory as the file that this is in.

I really appreciate your help on this.

like image 680
AppleTattooGuy Avatar asked Feb 13 '13 19:02

AppleTattooGuy


3 Answers

The path is relative to the file where the request was initiated. So, even if it's in the same folder as the file it's including, if that file was included from a file in a different folder, you will have to use an absolute path or a path relative to the original file.

like image 97
Josh Avatar answered Oct 20 '22 18:10

Josh


Try using include('./tweets.php');. If that does not resolve your issue, it's most likely file permissions. Give everyone full permissions for tweets.php and see if that works.

like image 44
neelsg Avatar answered Oct 20 '22 17:10

neelsg


As @Josh says, the path is relative to the file that received the request, so you can exploit the PHP __DIR__ magic constant:

include(__DIR__ . '/tweets.php');
like image 27
Andrea Avatar answered Oct 20 '22 18:10

Andrea