Re: Retrieving PDF/MSWord Files from Database

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

 



try this instead...

create a link like this 
<a href=download.php?id=143>download</a>

save this code as download.php:

<?php

$ID=$_GET['id'];
//add some security checking here then

$result = mysql_query("SELECT fileContent FROM
 research WHERE referenceid='$ID'") or die("MySQL
Query
 Error:".mysql_error()."<br><br>"."The SQL was:
 $SQL<br><br>");

         $resulta = mysql_fetch_array($result)or
 die("error: in fetch name".mysql_error());

        $filedata = $resulta[0];
        $mimetype="application/pdf";
        $filename="research.pdf";

         mysql_close($link);

if (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 5') or
        strpos($_SERVER['HTTP_USER_AGENT'],'Opera 7'))
      $mimetype = 'application/x-download';
  

  header("content-disposition: $disposition;    
filename=$filename");
  header("content-type: $mimetype");
  header('content-length: ' . strlen($filedata));

  echo($filedata);

?>         

hope this help you.

regards,
Pacey

--- Roderick Ramos� <roderick_ramos@xxxxxxxxx>
wrote:

> Hi Pacey,
> 
> Thank you for your reply. 
> 
> I tried doing as told but instead of the pdf file
> (from the database), the php file handling the
> download (the downloader or in this printscreen,
> "viewArticlesPage.php") was prompted ready for
> download (see attached image file). 
> 
> I am trying to avoid uploading files and storing
> them in a folder somewhere in the PC for this is
> less secured and might be deleted accidentaly. What
> do you think is the better way to do this? 
> 
> Thank you.
> 
> Regards, 
> 
> 
> Ricky
> 
> 
> Pacey Arcilla <westtalafreak@xxxxxxxxx> wrote:   
> it's not advisable to put the binary data in a
> session
>  variable.
>  
>  any way you can try this instead.
>  
>  <?php
>      header("Content-Type : application/pdf");
>      session_start();
>      $file = $_SESSION['resulta'];
>      header('Content-Disposition: attachment;
>  filename="research.pdf"');
>      echo $file;
>  ?>
>  
>  
>  --- Roderick Ramos� <roderick_ramos@xxxxxxxxx>
>  wrote:
>  
>  > Hello,
>  > 
>  > I am able to upload .pdf and .doc files into the
>  > MySQL database (using Medium Blob) but I can't
>  > retrieve or download them back. Can you help me
>  > download them?
>  > 
>  > What I did was the following pages
> (downloadpage.php
>  > and downloader.php):
>  > 
>  > 
>  > (1) downloadpage.php
>  > (trying to download pdf document with reference
>  > ID=143 from database)
>  > 
>  > ....
>  > 
>  > $result = mysql_query("SELECT fileContent FROM
>  > research WHERE referenceid=143") or die("MySQL
> Query
>  > Error:".mysql_error()."<br><br>"."The SQL was:
>  > $SQL<br><br>");
>  > 
>  >         $resulta = mysql_fetch_array($result)or
>  > die("error: in fetch name".mysql_error());
>  > 
>  >         $_SESSION['resulta'] = $resulta[0];
>  > 
>  >         mysql_close($link);
>  >         
>  >         ?>
>  >         
>  >                
>  >         <a href="downloader.php">download
>  > articles</a>
>  >             
>  > (2) downloader.php
>  > (process downloading)        
>  > 
>  > <?php
>  >     header("Content-Type : application/pdf");
>  >     session_start();
>  >     $file = $_SESSION['resulta'];
>  >     header('Content-Disposition: attachment;
>  > filename="research.pdf"');
>  >     readfile($file);
>  > ?>
>  > 
>  > 
>  > 
>  > 
>  > 
>  > Thank you very much!
>  > 
>  > 
>  > Regards,
>  > 
>  > Ricky
>  > 
>  > 
>  > 
>  >             
>  > ---------------------------------
>  > New Yahoo! Messenger with Voice. Call regular
> phones
>  > from your PC and save big.
>  > 
>  > [Non-text portions of this message have been
>  > removed]
>  > 
>  > 
>  
>  
>  __________________________________________________
>  Do You Yahoo!?
>  Tired of spam?  Yahoo! Mail has the best spam
> protection around 
>  http://mail.yahoo.com 
>  
>  
>      
> 
>   PHP Data object relational mapping generator
>  http://www.metastorage.net/ 
> 
>            
>       
> ---------------------------------
>    YAHOO! GROUPS LINKS 
>  
>     
>     Visit your group "php-objects" on the web.
>     
>     To unsubscribe from this group, send an email
> to:
>  php-objects-unsubscribe@xxxxxxxxxxxxxxx
>     
>     Your use of Yahoo! Groups is subject to the
> Yahoo! Terms of Service. 
>  
>     
> ---------------------------------
>  
>  
>      
> 
> 
> 
> 			
> ---------------------------------
> Yahoo! Messenger with Voice. PC-to-Phone calls for
> ridiculously low rates.
> 
> [Non-text portions of this message have been
> removed]
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.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