Re: How do you make a temporary download page?

From: Date: Fri, 09 May 2003 13:47:58 +0000
Subject: Re: How do you make a temporary download page?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147012@lists.php.net to get a copy of this message
At 15:29 09.05.2003, Brian Dunning said: --------------------[snip]-------------------- >I want to make a temporary download page, whereby someone completes >their credit card transaction and then is sent to a URL to download >their product, and the URL is valid for 60 minutes or 3 attempts. >Standard stuff. > >My background is in Lasso, not PHP. In Lasso they'd get a URL like: > > http://www.domain.com/download.lasso?id=sdhf63hgf > >which queries the db, and if it's still valid, the response is: > >[Header] > HTTP/1.0 200 OK > Server: Lasso 6 > Content-Type: application/pdf > Content-Disposition: attachment; filename="desiredfilename.pdf" >[/Header] >[Include_Raw: '/actualpathname/filenameonserver.abc'] > >Can it be done the same way in PHP, or do you have to use symbolic >links, cron jobs, etc.? Thanks, --------------------[snip]-------------------- Of course it can be done, provided that you are persistently mapping the id to the download permissions, maybe in a database, maybe in a script-generated config file that you include from download.php. Not using a database I'd store the download info in an associative array, something like that: $dlinfo = array( 'id' => 'sdhf63hgf', 'timeout' => time() + 3600, // now + 1 hour 'files' => array( // filename => file description 'master.doc' => 'The master document', 'prices.pdf' => 'Your personal product price list', // etc ), ); Then I'd serialize this array and store it in some temp path: $ser = serialize($dlinfo); $hf = fopen('/tmp/' . $dlinfo['id'] . '.dlinfo', 'w'); fwrite($hf, $ser); fclose($hf); In download.php, I'd get this file: $file = '/tmp/' . $_REQUEST['id'] . '.dlinfo'; $hf = fopen($file, 'r'); $ser = fread($hf, filesize($file)); fclose($hf); $dlinfo = unserialize($ser); To make sure it is not timed out, check the time: if ($dlinfo['time'] < time()) { unlink($file); $dlinfo = null; } Well, if the $dlinfo array exists at this point it is valid and contains all information for you to present a nice download page. Just make sure that the downloaded files are outside the DOCROOT folder so noone could access them directly. HTH, -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#147012) next »