Re: Retrieving PDF/MSWord Files from Database

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

 



1.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

If you're creating a download page for Internet
Explorer, the following code works:

   if(isset($_SERVER['HTTP_USER_AGENT']) &&
preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
       // IE Bug in download name workaround
       ini_set( 'zlib.output_compression','Off' );
   }
  
   header('Content-type: ' . $file['type']);
   header("Pragma: public");
   header("Cache-Control: must-revalidate,
post-check=0, pre-check=0");
   header('Content-Disposition: attachment;
filename="' . $file['filename'] . '"');
   print($file['data']);

I will note that setting content length or size
headers will cause IE to see the file being
opened/saved as 0 bytes and will on occasion open the
content of the file in the browser itself after the
download fails.

I also recieved file not found problems until I added
the Pragma and Cache-Control headers.

Yet another one of those "Thanks Bill" situations.

--james


this is the solution which i found on PHP.NET site...
on http://in.php.net/header page....
try this out.. if u r working on IE....

2.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

second suggestion.. is .. that rather than putting up
data into the session variable.. why don't u run the
query and fetch data in the viewarticlespage.php






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

> Hi,
> 
> I guess this yahoogroup does not allow attachments.
> Please allow me to copy and paste the codes below.
> Kindly check.  Thank you!
> 
> 
> REVIEWERPAGE.PHP
> 
> 
> <?php
>     session_start();
> ?>
> 
> 
> 
> <html>
> <head>
> </head>
> 
> <body>
> 
> <h3>REVIEWER's PAGE</h3>
> 
> <br><br>
> 
> Welcome <?php 
> 
>         $user="boom";
>         $pass="beech";
>         $db="journal";
> 
>         $link = mysql_connect("10.32.180.105",
> "$user", "$pass");
> 
>         if (!$link){
>     
>         die("Couldn't connect to MySQL:
> ".mysql_error());
>     
>         }
> 
>         @mysql_select_db($db) 
>         or die("Couldn't open $db:
> ".@mysql_error());    
> 
>         $getUserid = mysql_query("SELECT userid FROM
> user WHERE username='$loginName' AND
> password='$loginPassword'")
>         or die("error in getting userID:
> ".mysql_error());
>     
>         $useridHere = mysql_fetch_array($getUserid)
>         or die("error: in fetch
> name".mysql_error());
>         
>         $_SESSION['userid'] = $useridHere[0];
>         
>         
>         $name = mysql_query("SELECT
> registration.fname FROM user,registration WHERE
> user.userid=registration.userid AND
> user.userid=$useridHere[0]")
>         or die("error in getting name:
> ".mysql_error());
> 
>         $namePrint = mysql_fetch_array($name)
>         or die("error: in fetch
> name".mysql_error());
> 
>         print $namePrint[0];
>         
>         
>         
>         $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);
>         
>         ?>!
>         
>         <br><br>
>         
>         <a href="viewArticlesPage.php">review
> articles</a>
>             
>         <br><br>
>         
>         
>         <a href="pisika/authorPage.php">submit
> article</a>
>         
>         <br><br>
>         
>         <a href="loginPage.php">exit</a>
> 
> </body>
> 
> </html>
> 
> 
> VIEWARTICLESPAGE.PHP 
> 
> <?php
>     header("Content-Type : application/pdf");
>     session_start();
>     $file = $_SESSION['resulta'];
>     header('Content-Disposition: attachment;
> filename="research.pdf"');
>     echo $file;
> ?>
> 
> 
> 
> <?php
>     //header('Expires: Thu, 30 Nov 2007 08:52:00
> GMT');
>     //header('Cache-Control: must-revalidate,
> post-check=0, pre-check=0');
>     //header('Pragma: no-cache');
>     //header("Content-Type : application/pdf");
>     //session_start();
>     //$file = $_SESSION['resulta'];
>     //header('Content-Disposition: attachment;
> filename="research.pdf"');
>     //readfile($file);
>     //die();  
>     
>     
>     /*header('Expires: Thu, 30 Nov 2007 08:52:00
> GMT');
>     header('Cache-Control: must-revalidate,
> post-check=0, pre-check=0');
>     header('Pragma: no-cache');
>     header("Content-Type : application/pdf");
>     session_start();
>     $file = $_SESSION['resulta'];
>     header("Content-Disposition: attachment;
> filename=".$filename.".pdf");
>     readfile($file);
>     die();*/  
>     //header('Content-type: application/pdf');
>     //$file = $_SESSION['resulta'];
>     //header('Content-Disposition: attachment;
> filename='.$file);
>     //readfile($file);
> ?>
> 
> 
> <html>
> <head>
> </head>
> <body>
> </body>
> </html>
> 
> 
> 
> gaurav rustogi <gaurav_rustogi@xxxxxxxxxxx> wrote:  
>  can u mail the actual code.. so that it becomes
> easy
>  to figure out why instead of the pdf.. u r getting
> the
>  source file for download
>  
>  
>  --- 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:   
> 
=== message truncated ===


Send instant messages to your online friends http://uk.messenger.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