Re: Using PHP to send file through a http pipe?
| From: | Curt Zirzow | Date: | Sat, 25 Dec 2004 15:47:11 +0000 |
| Subject: | Re: Using PHP to send file through a http pipe? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-205185@lists.php.net to get a copy of this message | ||
* Thus wrote Jack:
>
> What I want to do is have a file (like get.php) which will read the file on
> the drive, and then transfer it through to the client on the browser. (ie:
> get.php?file=/atcommand.txt )
>
> Is there a simple way to do this while reducing security concerns? (Ie:
> reading ../../../../../etc/passwd )
This will do the trick:
http://php.net/realpath
$file = $_GET['file']; /* ../../../etc/passwd */
/* make sure its absolute. */
if ($file{0} != '/') {
$file = '/' . $file; /* /../../../etc/passwd */
}
$file = realpath($file); /* /etc/passwd */
/* just to be safe make it relative */
$file = substr($file, 1); /* etc/passwd */
/* and prefix your ftp path: */
$thefile = '/path/to/ftp/root/' . $file;
Curt
--
Quoth the Raven, "Nevermore."