当前位置:首页 > PHP教程 > PHP高级教程

php 强制下载文件实现代码

复制代码 代码如下:

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
    header('content-description: file transfer');
    header('content-type: application/octet-stream');
    header('content-disposition: attachment; filename='.basename($file));
    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($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>
?
<?php
header("content-type: application/force-download");
header("content-disposition: attachment; filename=ins.jpg"); 
readfile("imgs/test_zoom.jpg");
?>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!