My stackoverflow answer #6

by krike in Other / Stackoverflow answers on 08 Nov 2010

Each week I feature one of my answers on stackoverflow hoping it might help other people.

The question

This weeks question by Junaid Nisto: Forward slash in include/require doesn’t go to root

Isn’t for example this supposed to go to the server root on a site and get the sometext.txt from there?:

<?php require '/sometext.txt'; ?>

When I run this in a script, I get “failed to open stream: No such file or directory”.

I vaguely remember using the forward slash in a require/include function before, and that it has worked..

I use Apache as webserver.

My anwser

I think you need a dot in front of the slash

<?php require('./sometext.txt'); ?>

or something like this would be better

   require $_SERVER['DOCUMENT_ROOT'].'/sometext.txt';

Written by krike

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet nisl nisl. Ut interdum libero vitae quam ultricies et lacinia elit aliquet. Praesent tincidunt, sem tempus feugiat feugiat, turpis tellus scelerisque erat, sit amet feugiat neque arcu ac lectus. Sed at mi et elit interdum scelerisque vitae eu felis.

krike has written 77 posts.