I know by default you can not use an absolute path when using fopen and mkdir, but in my case I really need to specify the exact location of the files/directories.

I KNOW there must be some workaround way to do this... does anyone know how?

For example, here is what I am using now:

$path = "../../logs/".date("Y")."/".date("m"); 
$filename = date("M.d.Y").".txt";

	$openfile = fopen($path."/".$filename, 'a');
	fwrite($openfile, $logcontent);
	fclose($openfile);

This is working, but I need to do something like:

$path = "http://www.mydomain.com/logs/".date("Y")."/".date("m");

ANY help would be greatly appreciated!!

Recommended Answers

All 3 Replies

Im not sure if it works on a shared server, but i know it can be done on a vps or something you have root access to.

just put in the full path of the server eg:
/home/username/www.mydomain.com.au/myimages/imagename.jpg

It will only work though if the permissions of the user are set up right.

If you don't know the path to your document root you can use $_SERVER['DOCUMENT_ROOT']

$path = $_SERVER['DOCUMENT_ROOT']."/logs/".date("Y")."/".date("m");

NOTE: DOCUMENT_ROOT is blank on an IIS (Windows) web server.

I know by default you can not use an absolute path when using fopen and mkdir, but in my case I really need to specify the exact location of the files/directories.

I KNOW there must be some workaround way to do this... does anyone know how?

For example, here is what I am using now:

$path = "../../logs/".date("Y")."/".date("m"); 
$filename = date("M.d.Y").".txt";

	$openfile = fopen($path."/".$filename, 'a');
	fwrite($openfile, $logcontent);
	fclose($openfile);

This is working, but I need to do something like:

$path = "http://www.mydomain.com/logs/".date("Y")."/".date("m");

ANY help would be greatly appreciated!!

it seams that you want to rewrite url. isn't it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.