Jump to content

force download script failing with PDFs.


spiderwell

Recommended Posts

Hi guys

 

This one has been trouble for me for a qhile now, and I have tried various methods and none seem to work on pdf downloads, the file downloads only 1 byte or there abouts. All other files download ok , just PDFs seem not to.

here is my code, the $filecontrol->insertFileDownload() are  just database logs being inserted

 

 

<?php
ob_start();
session_start();
include("../classes/files.php");
$filecontrol = new FileControl();
$var_fileid = $_GET['fileid'];
$userid = (isset($_SESSION['userid'])) ? $_SESSION['userid'] : 0;
if ($userid == 0) die('you are not logged in');
if ($filecontrol->isFilePublic($var_fileid))
{
$file = "../filedump/" . $filecontrol->getFileName($var_fileid);
$filecontrol->insertFileDownload($var_fileid,$userid,true);

}
else
{
if ($filecontrol->doesUserHaveRights($var_fileid))
{
	$file = "../filedump/" . $filecontrol->getFileName($var_fileid);
	$filecontrol->insertFileDownload($var_fileid,$userid,true);

}
else
{
	$file = "../filedump/" . "norights.txt";
	$filecontrol->insertFileDownload($var_fileid,$userid,false);
}
}
$file_extension = strtolower(substr(strrchr($file,"."),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;
  case "xls": $ctype="application/vnd.ms-excel"; break;
  case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
  case "gif": $ctype="image/gif"; break;
  case "png": $ctype="image/png"; break;
  case "jpeg":
  case "jpg": $ctype="image/jpg"; break;
  default: $ctype="application/force-download";
}

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-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
readfile("$file");
exit();

 

thanks for reading

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.