Jump to content

download with code


glenelkins

Recommended Posts

Hi,

try this... just set the content dispositsion and the file name etc

[code]

<?php

  function downloadFile($thefile, $ctype, $dname) {
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Cache-Control: public");
      header("Content-Description: File Transfer");
      header("Content-type: ".$ctype);
      header("Content-Length: ".filesize($thefile));
      header("Content-Disposition: attachment; filename=\"".$dname."\"");
      header("Content-Transfer-Encoding: binary");
      $fp = fopen($thefile);
      fpassthru($fp);
      fclose($fp);
  }

$thefile = "HSC21.pdf";
$ctype = "application/pdf";
$dname = "HSC21.pdf";

downloadFile($thefile, $ctype, $dname);
?>

[/code]

Cheers

Tim Perrett
Link to comment
https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-12692
Share on other sites

ok cheers. is there a function to test a files extension? as i am wanting to allow downloads of multiple file types so:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$ctype = "application/pdf";[/quote]

wot quite be good enough
Link to comment
https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-12695
Share on other sites

  • 3 months later...

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.