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

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.