Question

So I'm attempting to use include. Here's my index.php

<?php
include ("r.php");
?>

As you can see it simply includes r.php. And here's my r.php

<?php
echo "This is the included code";
?>

This is where the files are both located enter image description here

So when I run index.php I get

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

I've also tried include "r.php";, note the parentheses, but I'd still get the same error. Any ideas?

Était-ce utile?

La solution

Try using the absolute path for r.php and that should work

Autres conseils

Use this to include the file relative to the current file:

include ($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'r.php');

Also, make sure that the webserver has permission to view that file.

Edit: Use abolute path

Try finding your current working directory. Then appending the source code path and then your file. Keep in mind directory separators are different for different OS's

$ds = "\\"; // if your on a windows machine
include(getcwd().$ds.$sourceCodeDirPath.$ds."r.php");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top