rondog Posted October 15, 2007 Share Posted October 15, 2007 I am suppose to be presenting this tomorrow and just realized its not working in Internet explorer! I am in a flash app that when you click the link it open readpdf.php <?php session_start(); if ($_SESSION['approved'] != 'yes') { header("Location: dlerror.php"); } else { $filename = $_POST['fname']; $filename = realpath("8d46y2g1/".$filename); $file_extension = strtolower(substr(strrchr($filename,"."),1)); switch ($file_extension) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; default: $ctype="application/force-download"; } if (!file_exists($filename)) { die("NO FILE HERE"); } // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize(basename($filename))); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";"); set_time_limit(0); @readfile("$filename") or die("File not found."); } ?> What that script basically does is a force download of the pdf file. In firefox, the save dialog comes up and I am able to save it or just open it fine. In internet explorer if you hit open it says the file is corrupt and if you save it, the file size is 0kb. Any reason this is happening? I am desperate please!!!! Quote Link to comment https://forums.phpfreaks.com/topic/73279-solved-big-problem-with-readfile-need-help-fast/ Share on other sites More sharing options...
drewjoh Posted October 15, 2007 Share Posted October 15, 2007 Just a quick guess, but doesn't this line: <?php header("Content-Length: ".filesize(basename($filename))); ?> need to be: <?php header("Content-Length: ".filesize($filename)); ?> Seems like to get the filesize, you need to link to the file with the directory path, otherwise it's looking in your current working directory? Quote Link to comment https://forums.phpfreaks.com/topic/73279-solved-big-problem-with-readfile-need-help-fast/#findComment-369720 Share on other sites More sharing options...
rondog Posted October 15, 2007 Author Share Posted October 15, 2007 well that was the problem. I dont understand why it worked in firefox but not IE...thanks so much you just saved me! Quote Link to comment https://forums.phpfreaks.com/topic/73279-solved-big-problem-with-readfile-need-help-fast/#findComment-369722 Share on other sites More sharing options...
drewjoh Posted October 15, 2007 Share Posted October 15, 2007 I think IE tries to match up the said filesize with the actual size of the content it's being given, and if it doesn't match: it fails. Whereas Firefox will just deal with it. Something to that effect... Seems like a good while ago I was doing something similar. Good luck with your presentation! Quote Link to comment https://forums.phpfreaks.com/topic/73279-solved-big-problem-with-readfile-need-help-fast/#findComment-369728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.