Home > Archive > PHP with PostgreSQL > November 2005 > Automatically opening pdf files stored in a bytea field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Automatically opening pdf files stored in a bytea field
Adam Witney

2005-10-27, 8:14 am


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($stat
2, 0);

header("Content-type: application/pdf");
header('Content-Disposition: attachment;
filename="'.$data['filename'].'"');

echo pg_unescape_bytea($d
ata['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.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Volkan YAZICI

2005-10-27, 8:14 am

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.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Christopher Kings-Lynne

2005-10-27, 8:14 am

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($stat
2, 0);
>
> header("Content-type: application/pdf");
> header('Content-Disposition: attachment;
> filename="'.$data['filename'].'"');
>
> echo pg_unescape_bytea($d
ata['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
>
>



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Volkan YAZICI

2005-10-27, 8:14 am

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.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Christopher Kings-Lynne

2005-10-27, 8:15 am

> 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


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Marcus Krause

2005-11-02, 3:24 am

Am 11.10.2005 12:58, Adam Witney schrieb:
> 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


Besides using the right header declaration I do normally add following
GET-parameter to the script that generates the pdf-file: file=.pdf

And finally something like anyfile.php?anyparameter=4&file=.pdf works
fine also for ie-users!

Magkes
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com