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.
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.
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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With