Web/PHP

php 파일 다운로드 (pdf 파일 다운로드 예), php file download

또만났네 2017. 4. 6. 17:59
반응형

php file download


<?

include"./system.php";





$dir = './duri/goods/pdf';

$filekeyname = $_GET['filekeyname'];

$fpath = $dir."/".$filekeyname;

$filename = preg_replace("/\s| /",'',$_GET['filename']).".pdf";

//echo $fpath;

//exit;



if (file_exists($fpath)) {

    header('Content-Description: File Transfer');

    header('Content-Type: application/octet-stream');

    header("Content-Type: application/force-download");

    header('Content-Disposition: attachment; filename=' . urlencode(basename($filename)));

    // header('Content-Transfer-Encoding: binary');

    header('Expires: 0');

    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

    header('Pragma: public');

    header('Content-Length: ' . filesize($fpath));

    ob_clean();

    flush();

    readfile($fpath);

    exit;

}


?>


반응형