PHP File Access Query

Soldato
Joined
13 Feb 2003
Posts
4,353
Location
Over the Moon
Hey guys, I currently have a Windows box with PHP, and was just wondering how I could create a link to access a file below the wwwroot directory so that things are kept a little more secure?

I'm probably being thick on this one, but any help would be greatly appreciated!

Cheers :)
 
Call download.php?file=xyz.ext

PHP:
<?php
	$file = basename($_GET['file']);
	if(file_exists('../' . $file))
	{
		$fp = fopen('../' . $file, 'r');
		while($buffer = fread($fp, 1024))
		{
			echo $buffer;
		}	
	}
	else
		header("HTTP/1.1 404 Not Found");

note: closeing ?> left out as it's not required (and not recommended for purely PHP files)
 
Ahh thanking you very much, I tried something similar yesterday but gave up all hope of getting it working!

Shall give this a go later :)
 
Back
Top Bottom