Saturday, September 6, 2008

Inline-download problem with IE browsers

IE's problem again faces some criticism to my part. I came up of this snippet
that does an inline download of a file.

Adding of
header("Cache-Control: maxage=1"); //In seconds
header("Pragma: public");
heals the problem when a file is in buffer at the client's browser. Problem occurs here is when a
user attempts to open a file, it does tells that the file sort of not found or whatever Microsoft tells.

"

filename = unique_string(8);


$fp = fopen("/tmp/{$filename}", 'w');
fwrite($fp, $contents);
fclose($fp);

header("Cache-Control: maxage=1"); //In seconds
header("Pragma: public");
header( 'Content-Type: ' . 'application/pdf' );
header( 'Content-Disposition: inline; filename="' . basename("/tmp/{$filename}") . '.pdf' . '"');
// Add the rest of the headers
header( 'Cache-Control: public' );
header( 'Content-Transfer-Encoding: binary' );
header("Content-Length: " . filesize("/tmp/{$filename}"));

readfile("/tmp/{$filename}");
unlink("/tmp/{$filename}");

"

Viewing the file through an inline-download is over HTTPS so this is a SSL problem with IE.

Detecting plugins for pdf


I just found this site that can detect acrobat reader in browser plugins.
Here's the link: http://gemal.dk/browserspy/acrobat.html

Viewing the source code of that page, i found these lines in the script which does the detection of pdf plugin.

<object id="ocx_pdf" classid="clsid:{CA8A9780-280D-11CF-A24D-444553540000}" style="display:none"></object>
<script type="text/javascript"><!--
var i_acrobatreader;

var v_acrobatreader;

var a_acrobatreader;

if (obj(navigator.plugins)) {

for (var i=0; i < navigator.plugins.length; i++) {

if (navigator.plugins[i].name.toLowerCase().indexOf("adobe acrobat") >= 0) {

i_acrobatreader = true;

v_acrobatreader = navigator.plugins[i].description.substring(navigator.plugins[i].description.toLowerCase().lastIndexOf("version ") + 8, navigator.plugins[i].description.toLowerCase().lastIndexOf(" for"));

break;

}

}

}

// --></script>

<script type="text/vbscript"><!--

on error resume next

num = 0

myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")

do until num = 6

set tmp = CreateObject(myarray(num))

if IsObject(tmp) then

i_acrobatreader = true

v_acrobatreader = num

end if

num = num + 1

loop

if IsObject(ocx_pdf) and i_acrobatreader then

a_acrobatreader = ocx_pdf.GetVersions

end if

// --></script>

....

<script type="text/javascript"><!--

if (i_acrobatreader) {

document.writeln("Yes");

if (v_acrobatreader) {

document.writeln(" - version " + v_acrobatreader);

}

} else {

document.writeln("No or unable to detect...");

}

// --></script>



....



<script type="text/javascript"><!--

if (i_acrobatreader) {

if (a_acrobatreader) {

var comps = a_acrobatreader.split(",");

for (var i = 0; i < comps.length; i++) {

var detail = comps[i].split("=");

if (detail[0])

document.writeln(detail[0] + " version " + detail[1]+"<br />");

}

} else {

document.writeln("Unable to detect...");

}

} else {

document.writeln("Acrobat Reader not installed.");

}

// --></script>


In my previous applications, by garnering some concepts from other snippets, I came up to this:

<script language="javascript" type="text/javascript">
<!--
    /*<![CDATA[*/
    var hasAcrobat = navigator.mimeTypes && navigator.mimeTypes["application/pdf"];
    /*]]>*/
//-->
</script>  <script type="text/vbscript">
<!--

on error resume next
num = 0
myarray = array("PDF.PdfCtrl.1", "PDF.PdfCtrl.2", "PDF.PdfCtrl.3", "PDF.PdfCtrl.4", "PDF.PdfCtrl.5", "PDF.PdfCtrl.6", "PDF.PdfCtrl.7")
do until num = 6
    set tmp = CreateObject(myarray(num))
    if IsObject(tmp) then
        hasAcrobat = true
        v_acrobatreader = num
    end if
    num = num + 1
loop

// -->
</script>  <script language="javascript" type="text/javascript">
<!--
    /*<![CDATA[*/

   
    if (! hasAcrobat) {
        window.location = '<?=$_SERVER['REQUEST_URI']?>&forceDL';
    } else {
        window.location = 'some_php_script.php?filesrc=<?=base64_encode($sourceDoc)?>';
    }
    /*]]>*/
//-->
</script>

Tuesday, September 2, 2008

CSS Hide Background

I just found this css snippet to somewhat like disabling the elements behind if a dialog box appears.

/* Enables to disable elements behind */
.somethingDialogUnderlayWrapper {
position: absolute;
left: 0px;
top: 0px;
z-index: 998;
display: none;
background: transparent;
}

/* colors to a disabled-color */
.somethingDialogUnderlay {
background: #eeeeee;
opacity: 0.5;
}