Re: download script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi andres,

firstly u need to find out thru php code (explode)
function the extension of the file and accordingly
send the content-type header to browser and then send
in second header which tells the browser that the
content is supposed to be downloaded.. i.e. done thru
the disposition header....

bye,
Gaurav Rustogi
--- Andres Santos <asantos@xxxxxxxxx> wrote:

> hi, i coded some basic file downloader (for word,
> excel, powerpoint,
> pdf, etc files). My question is, do i have to use a
> special header
> before sending the file to the user in the http
> request? this is the
> code:
> 
> <?php
> $id = $_GET['id'];
> if(!is_numeric($id)) {
> 	header('Location: '.$_SERVER['HTTP_REFERER']);
> 	die();
> }
> # Verify that file linked to the ID exists
> $sql = 'SELECT * FROM files WHERE id = '.$id;
> $rs = &$cnn->Execute($sql);
> if (!$rs->EOF) {
> 	# File exists
> 	$record = array();
> 	# Increments download-times count
> 	$record['downloads'] = $rs->fields['downloads']+1;
> 	$sql = $cnn->GetUpdateSQL($rs, $record);
> 	$cnn->Execute($sql);
> 	header('Location:
> /files/'.basename($rs->fields['filename']));
> 	die();
> } else {
> 	# File doesn't exist
> 	header('Location: '.$_SERVER['HTTP_REFERER']);
> 	die();
> }
> ?>
> 
> As you can see, im only using header to redirect the
> user to the FILE
> itself. Is that ok? or do i have to set some kind of
> binary header?
> 
> Thanks,
> Andres
> 
> 
> 
> --
> Slds,
> Andrés Santos, IIG
> 
> *****************************
> cel: (593) 9 7026627
> http://www.egobits.com
> *****************************
> 
> 
> PHP Data object relational mapping generator
> http://www.metastorage.net/ 
> Yahoo! Groups Links
> 
> 
>     php-objects-unsubscribe@xxxxxxxxxxxxxxx
> 
>  
> 
> 
> 



		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com


PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux