PHP & include_path

software development

#1

Hello all,
I’m new to php and trying to create and write a file at root level.

I used the .pcgi file extension for the php file and also used:
include($_SERVER[‘DOCUMENT_ROOT’]."/counter/counter.txt");

when I try to create and open the file with:
$thisfile= fopen("$DOCUMENT_ROOT/…/counter/counter.txt",“w+”);

I get this error:
Warning: Failed opening ‘/home/user/xramblex.com/counter/counter.txt’ for inclusion (include_path=’.’)

when I try with:
$thisfile= fopen($_SERVER[‘DOCUMENT_ROOT’]."/counter/counter.txt");
I get a php error.

What’s the proper way in DH to create and access that folder and file?

Thanks,
Brad


#2

I have the standard DOCUMENT_ROOT function to work…
using that for reading and writing for now.

If anyone has the correct DH syntax to fopen a file at root level (using the $_SERVER[‘DOCUMENT_ROOT’], please post a sample line of code.

many thanks,
Brad


#3

Here’s what I use, which works just fine:

include($_SERVER[‘DOCUMENT_ROOT’]."/PATH/TO/FILE.php");

Is this what you were after?


#4

Gabe,

Thanks for your reply.

Correctly stated, what I really needed to do was to open a file, not include it. My mistake. After trial and error the proper syntax to open a file one level up from the root is:

fopen($_SERVER[‘DOCUMENT_ROOT’]."/…/path/file.txt",“r+”);

Hope this helps other beginners working w/ php and DH.