pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Automatically opening pdf files stored in a bytea field
9+ messages / 5 participants
[nested] [flat]

* Automatically opening pdf files stored in a bytea field
@ 2005-10-11 10:58 Adam Witney <awitney@sgul.ac.uk>
  2005-10-11 11:30 ` Re: Automatically opening pdf files stored in a bytea Frank Bax <fbax@sympatico.ca>
  2005-10-11 17:56 ` Re: Automatically opening pdf files stored in a bytea field Volkan YAZICI <volkan.yazici@gmail.com>
  2005-10-12 01:29 ` Re: Automatically opening pdf files stored in a bytea field Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 3 replies; 9+ messages in thread

From: Adam Witney @ 2005-10-11 10:58 UTC (permalink / raw)
  To: pgsql-php


Hi,

This may be off-topic as regards the database aspect, but im sure people on
this list must come across this problem.

I have PDF files stored in a bytea field in the database and I want to all
the user to click a link on the web page and have the file automatically
opened in acrobat (or whatever they have set to read the pdf). It works for
most browsers except for in Internet Explorer on windows (surprise
surprise!). Here is my code

 $sql_data = "SELECT filename, file_data FROM dba_suppl WHERE dba_suppl_id =
".$dba_suppl_id.";";
             
 if($stat2 = execute($sql_data))
    {
     if($rows = pg_numrows($stat2))
        {          
         $data = pg_fetch_array($stat2, 0);
                   
         header("Content-type: application/pdf");
         header('Content-Disposition: attachment;
filename="'.$data['filename'].'"');
                   
         echo pg_unescape_bytea($data['file_data']);
        }
    }

If I click it it opens acrobat but acrobat gives an error. If I right click
the link and save to disk I can open the file from there no problem. As I
say, on my mac and on FireFox on windows it does the right thing... Its just
IE on windows!

Is there something I am forgetting to do here? Or is it just IE and there is
no way around it??

Thanks for any help

Adam


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
@ 2005-10-11 11:30 ` Frank Bax <fbax@sympatico.ca>
  2005-10-11 15:52   ` Re: Automatically opening pdf files stored in a bytea operationsengineer1@yahoo.com
  2005-10-11 19:47   ` Re: Automatically opening pdf files stored in a bytea Adam Witney <awitney@sgul.ac.uk>
  2005-10-12 12:28   ` Re: Automatically opening pdf files stored in a bytea Adam Witney <awitney@sgul.ac.uk>
  2 siblings, 3 replies; 9+ messages in thread

From: Frank Bax @ 2005-10-11 11:30 UTC (permalink / raw)
  To: pgsql-php

At 06:58 AM 10/11/05, Adam Witney wrote:
>I have PDF files stored in a bytea field in the database and I want to all
>the user to click a link on the web page and have the file automatically
>opened in acrobat (or whatever they have set to read the pdf). It works for
>most browsers except for in Internet Explorer on windows (surprise
>surprise!). Here is my code
>
>          header("Content-type: application/pdf");
>          header('Content-Disposition: attachment; 
> filename="'.$data['filename'].'"');


Here's mine...
         if(isset($_SERVER['HTTP_USER_AGENT']) &&
                         strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
                 header('Content-Type: application/force-download');
         else
                 header('Content-Type: application/octet-stream');
         header('Content-Length: '.strlen($this->buffer));
         header('Content-disposition: attachment; filename="'.$name.'"');


But on a some systems (both Win98 & WinXP), user must save/open instead of 
open directly - haven't figured out why yet.  




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
  2005-10-11 11:30 ` Re: Automatically opening pdf files stored in a bytea Frank Bax <fbax@sympatico.ca>
@ 2005-10-11 15:52   ` operationsengineer1@yahoo.com
  2 siblings, 0 replies; 9+ messages in thread

From: operationsengineer1@yahoo.com @ 2005-10-11 15:52 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; pgsql-php

--- Frank Bax <fbax@sympatico.ca> wrote:

> At 06:58 AM 10/11/05, Adam Witney wrote:
> >I have PDF files stored in a bytea field in the
> database and I want to all
> >the user to click a link on the web page and have
> the file automatically
> >opened in acrobat (or whatever they have set to
> read the pdf). It works for
> >most browsers except for in Internet Explorer on
> windows (surprise
> >surprise!). Here is my code
> >
> >          header("Content-type: application/pdf");
> >          header('Content-Disposition: attachment; 
> > filename="'.$data['filename'].'"');
> 
> 
> Here's mine...
>          if(isset($_SERVER['HTTP_USER_AGENT']) &&
>                         
> strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
>                  header('Content-Type:
> application/force-download');
>          else
>                  header('Content-Type:
> application/octet-stream');
>          header('Content-Length:
> '.strlen($this->buffer));
>          header('Content-disposition: attachment;
> filename="'.$name.'"');
> 
> 
> But on a some systems (both Win98 & WinXP), user
> must save/open instead of 
> open directly - haven't figured out why yet.  
> 
> 
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org

i have had very good success storing links to pdf
files in the database and storing the actual files in
the locations pointed to by the link.

my application is work instructions - i have a naming
convention that i use so once you know the part
number, you know the name of the pdf if it exists.

i have two types of pdf documents and a name prefix
differentiates them from each other.

both firefox and ie will open these pdfs as expected.

if this approach makes sense for your application, you
may want to try it.


		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
  2005-10-11 11:30 ` Re: Automatically opening pdf files stored in a bytea Frank Bax <fbax@sympatico.ca>
@ 2005-10-11 19:47   ` Adam Witney <awitney@sgul.ac.uk>
  2 siblings, 0 replies; 9+ messages in thread

From: Adam Witney @ 2005-10-11 19:47 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; pgsql-php

On 11/10/05 12:30 pm, "Frank Bax" <fbax@sympatico.ca> wrote:

> At 06:58 AM 10/11/05, Adam Witney wrote:
>> I have PDF files stored in a bytea field in the database and I want to all
>> the user to click a link on the web page and have the file automatically
>> opened in acrobat (or whatever they have set to read the pdf). It works for
>> most browsers except for in Internet Explorer on windows (surprise
>> surprise!). Here is my code
>> 
>>          header("Content-type: application/pdf");
>>          header('Content-Disposition: attachment;
>> filename="'.$data['filename'].'"');
> 
> 
> Here's mine...
>        if(isset($_SERVER['HTTP_USER_AGENT']) &&
>                        strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
>                header('Content-Type: application/force-download');
>        else
>                header('Content-Type: application/octet-stream');
>        header('Content-Length: '.strlen($this->buffer));
>        header('Content-disposition: attachment; filename="'.$name.'"');
> 
> 
> But on a some systems (both Win98 & WinXP), user must save/open instead of
> open directly - haven't figured out why yet.

From the link sent by Volkan, adding these header lines fixes the problem

 header("Pragma: public");
 header("Expires: 0");
 header("Cache-Control: private");

Thanks for the help guys

Adam


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
  2005-10-11 11:30 ` Re: Automatically opening pdf files stored in a bytea Frank Bax <fbax@sympatico.ca>
@ 2005-10-12 12:28   ` Adam Witney <awitney@sgul.ac.uk>
  2 siblings, 0 replies; 9+ messages in thread

From: Adam Witney @ 2005-10-12 12:28 UTC (permalink / raw)
  To: Frank Bax <fbax@sympatico.ca>; pgsql-php


I sent this but it didn't seem to appear....

> At 06:58 AM 10/11/05, Adam Witney wrote:
>> I have PDF files stored in a bytea field in the database and I want to all
>> the user to click a link on the web page and have the file automatically
>> opened in acrobat (or whatever they have set to read the pdf). It works for
>> most browsers except for in Internet Explorer on windows (surprise
>> surprise!). Here is my code
>> 
>>          header("Content-type: application/pdf");
>>          header('Content-Disposition: attachment;
>> filename="'.$data['filename'].'"');
> 
> 
> Here's mine...
>        if(isset($_SERVER['HTTP_USER_AGENT']) &&
>                        strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
>                header('Content-Type: application/force-download');
>        else
>                header('Content-Type: application/octet-stream');
>        header('Content-Length: '.strlen($this->buffer));
>        header('Content-disposition: attachment; filename="'.$name.'"');
> 
> 
> But on a some systems (both Win98 & WinXP), user must save/open instead of
> open directly - haven't figured out why yet.

From the link sent by Volkan, adding these header lines fixes the problem

 header("Pragma: public");
 header("Expires: 0");
 header("Cache-Control: private");

Thanks for the help guys

Adam


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea field
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
@ 2005-10-11 17:56 ` Volkan YAZICI <volkan.yazici@gmail.com>
  2 siblings, 0 replies; 9+ messages in thread

From: Volkan YAZICI @ 2005-10-11 17:56 UTC (permalink / raw)
  To: Adam Witney <awitney@sgul.ac.uk>; +Cc: pgsql-php

Hi,

On 10/11/05, Adam Witney <awitney@sgul.ac.uk> wrote:
> I have PDF files stored in a bytea field in the database and I want to all
> the user to click a link on the web page and have the file automatically
> opened in acrobat (or whatever they have set to read the pdf).

Look at header() function's manual page [1] for PDF files. You'll see
lots of IE related problems and their fixes there.

[1] http://tr2.php.net/manual/en/function.header.php

Regards.



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea field
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
@ 2005-10-12 01:29 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2005-10-12 17:08   ` Re: Automatically opening pdf files stored in a bytea field Volkan YAZICI <volkan.yazici@gmail.com>
  2 siblings, 1 reply; 9+ messages in thread

From: Christopher Kings-Lynne @ 2005-10-12 01:29 UTC (permalink / raw)
  To: Adam Witney <awitney@sgul.ac.uk>; +Cc: pgsql-php

I'm not 100% sure you need the pg_unescape_bytea - I thought that was 
already done automatically?

Chris

Adam Witney wrote:
> Hi,
> 
> This may be off-topic as regards the database aspect, but im sure people on
> this list must come across this problem.
> 
> I have PDF files stored in a bytea field in the database and I want to all
> the user to click a link on the web page and have the file automatically
> opened in acrobat (or whatever they have set to read the pdf). It works for
> most browsers except for in Internet Explorer on windows (surprise
> surprise!). Here is my code
> 
>  $sql_data = "SELECT filename, file_data FROM dba_suppl WHERE dba_suppl_id =
> ".$dba_suppl_id.";";
>              
>  if($stat2 = execute($sql_data))
>     {
>      if($rows = pg_numrows($stat2))
>         {          
>          $data = pg_fetch_array($stat2, 0);
>                    
>          header("Content-type: application/pdf");
>          header('Content-Disposition: attachment;
> filename="'.$data['filename'].'"');
>                    
>          echo pg_unescape_bytea($data['file_data']);
>         }
>     }
> 
> If I click it it opens acrobat but acrobat gives an error. If I right click
> the link and save to disk I can open the file from there no problem. As I
> say, on my mac and on FireFox on windows it does the right thing... Its just
> IE on windows!
> 
> Is there something I am forgetting to do here? Or is it just IE and there is
> no way around it??
> 
> Thanks for any help
> 
> Adam
> 
> 




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea field
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
  2005-10-12 01:29 ` Re: Automatically opening pdf files stored in a bytea field Christopher Kings-Lynne <chriskl@familyhealth.com.au>
@ 2005-10-12 17:08   ` Volkan YAZICI <volkan.yazici@gmail.com>
  2005-10-13 02:13     ` Re: Automatically opening pdf files stored in a bytea field Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 1 reply; 9+ messages in thread

From: Volkan YAZICI @ 2005-10-12 17:08 UTC (permalink / raw)
  To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>; +Cc: Adam Witney <awitney@sgul.ac.uk>; pgsql-php

Hi,

On 10/12/05, Christopher Kings-Lynne <chriskl@familyhealth.com.au> wrote:
> I'm not 100% sure you need the pg_unescape_bytea - I thought that was
> already done automatically?

Yep, I agree. Furthermore, (un)escape routines will consume so much
system CPU. If you can, try to use parameters (pg_query_params() and
pg_send_params()) in any bytea/lo storage. This makes you free from
escaping without any potential SQL Injection threats.

Regards.



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Automatically opening pdf files stored in a bytea field
  2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
  2005-10-12 01:29 ` Re: Automatically opening pdf files stored in a bytea field Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2005-10-12 17:08   ` Re: Automatically opening pdf files stored in a bytea field Volkan YAZICI <volkan.yazici@gmail.com>
@ 2005-10-13 02:13     ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 0 replies; 9+ messages in thread

From: Christopher Kings-Lynne @ 2005-10-13 02:13 UTC (permalink / raw)
  To: Volkan YAZICI <volkan.yazici@gmail.com>; +Cc: Adam Witney <awitney@sgul.ac.uk>; pgsql-php

> Yep, I agree. Furthermore, (un)escape routines will consume so much
> system CPU. If you can, try to use parameters (pg_query_params() and
> pg_send_params()) in any bytea/lo storage. This makes you free from
> escaping without any potential SQL Injection threats.

PostgreSQL prepared statements don't escape bytea afaik

Chris




^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2005-10-13 02:13 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-11 10:58 Automatically opening pdf files stored in a bytea field Adam Witney <awitney@sgul.ac.uk>
2005-10-11 11:30 ` Re: Automatically opening pdf files stored in a bytea Frank Bax <fbax@sympatico.ca>
2005-10-11 15:52   ` Re: Automatically opening pdf files stored in a bytea operationsengineer1@yahoo.com
2005-10-11 19:47   ` Re: Automatically opening pdf files stored in a bytea Adam Witney <awitney@sgul.ac.uk>
2005-10-12 12:28   ` Re: Automatically opening pdf files stored in a bytea Adam Witney <awitney@sgul.ac.uk>
2005-10-11 17:56 ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-10-12 01:29 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-10-12 17:08   ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-10-13 02:13     ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox