Jump to content

[SOLVED] BIG problem with readfile!! Need help fast!


rondog

Recommended Posts

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!!!!

 

 

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?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.