Re: Re: HTTP_download : open file in browser, not download
| From: | Michael Wallner | Date: | Tue, 01 Jun 2004 10:36:07 +0000 |
| Subject: | Re: Re: HTTP_download : open file in browser, not download | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12811@lists.php.net to get a copy of this message | ||
I wrote:
> Hm, give me a minute to test with IIS - do you run PHP as CGI or module?
Ok, I think if extracted the real problem.
Win2k, IIS 5, PHP 4.3.6 as ISAPI, Windows Auth enabled
While it works like a charm with Mozilla, which renders the output
immediatly after posting the request, IE tries to fetch the PDF
with an intermediate HTML, which body solely consists of an <EMBED /> element:
<EMBED src=http://localhost:8080/tests/dl-pdf.php
width="100%" height="100%" type=application/pdf fullscreen="yes">
I captured this with typing "javascript:void(alert(document.body.innerHTML));"
into the address field. This *cannot* work because we/you check for the
presence of some $_POST variable. While this is not really true (I cannot
really describe IE's odd behaviour here...) here comes the hack:
Define a GET variable in the action of your form and check for that to start
the download process:
HTML: <form action="download.php?download=true" method="post">
PHP: if (isset($_GET['download']) // start download
HTH,
--
Michael - < mike(@)php.net >
--- Message from Vincent Blavet: ---
Both commands mean by setting the mime type myself or using the Guess
The Acrobat reader opens in a new window.
I use PHP as a ISAPI module, with Windows Integrated authentication (but
this should not disturb the process or opening/downloading the file)
All files HAVE the pdf file extension in their filename.
The files are located on Windows shares (samba) like
\\server\\share\file.pdf where the scripts may access and read the file
Thank you,
Below is the script download.php that I use to open/download the files
and the form to trigger the open/download :
<?php
require_once("HTTP/Download.php");
if(isset($_POST['download_file'])){
$file = $_POST['download_file'];//path to the file
$dl = & new HTTP_Download();
$the_file = $dl->setFile($file, false);
if(PEAR::isError($the_file)){
onError();
}
else{
$dl->setContentDisposition(HTTP_DOWNLOAD_INLINE);//HTTP_DOWNLOAD_ATTACHM
ENT( BOTH DO THE SAME OUTPUT)
$dl->setContentType("application/pdf");
//$dl->guessContentType();
$res = $dl->send();
if (PEAR::isError($res)){
onError();
}
}
}
function onError(){
$msg = '<b>File not available</b> :
'.$_POST['download_file'].'<br />
<a href="javascript:history.go(-1)">Please click
here to go to the previous page</a>
';
die($msg);
}
?>
Here is the HTML form that is embedded into a larger page, and where the
user should be able to open/download the file. now I need to
automatically open rather that download or promptfor user choice :
<form method="post" name="download_form1" action="download.php">
<input type="hidden" name="download_file"
value="\\server\share\folder\wet54g_eu_ug.pdf" />
<input type="submit" name="submit_download"
value="wet54g_eu_ug.pdf"
class="submitButton" />
</form>
-----Original Message-----
From: Michael Wallner [mailto:mike@php.net]
Sent: mardi 1 juin 2004 11:55
To: pear-general@lists.php.net
Subject: Re: [PEAR] Re: HTTP_download : open file in browser, not
download
Hi Vincent Dupont, you wrote:
>> Hi Mike, thanks for your interest
>>
>> I send a PDF file and use the $dl->guessContentType(); to send the
>> mime type. I also tried $dl->setContentType("application/pdf"); with
>> same result.
>>
>> When selecting 'open' in the prompt, PDF is correctly opened in
>> Adbode PDF reader with both commands
Within the browser (plugin) or is the reader starting externally?
What do you mean by "both commands"?
>> I updated my PEAR packages to the lastest version of HTTP_Header and
>> HTTP_download (beta) The browser always display the prompt twice if I
>> click 'open' and only once if I click 'Save'
Hm, give me a minute to test with IIS - do you run PHP as CGI or module?
>> what do you mean with the IE hack? i don't know this...
Well, IE often gives the file extension more weight than
the content type headers, so it's commonly used practice
to fake a file extension in the download URL.
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc