Обсуждение: Automatically opening pdf files stored in a bytea field

Поиск
Список
Период
Сортировка

Automatically opening pdf files stored in a bytea field

От
Adam Witney
Дата:
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.


Re: Automatically opening pdf files stored in a bytea

От
Frank Bax
Дата:
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.


Re: Automatically opening pdf files stored in a bytea

От
Дата:
--- 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

Re: Automatically opening pdf files stored in a bytea field

От
Volkan YAZICI
Дата:
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.

Re: Automatically opening pdf files stored in a bytea

От
Adam Witney
Дата:
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.


Re: Automatically opening pdf files stored in a bytea field

От
Christopher Kings-Lynne
Дата:
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
>
>


Re: Automatically opening pdf files stored in a bytea

От
Adam Witney
Дата:
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.


Re: Automatically opening pdf files stored in a bytea field

От
Volkan YAZICI
Дата:
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.

Re: Automatically opening pdf files stored in a bytea field

От
Christopher Kings-Lynne
Дата:
> 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