记录实用有价值的内容

PHP 隐藏文件实际下载地址的方法

php隐藏实际地址的文件下载方法

方法一:

function download_document($filename, $path = "", $mimetype = "application/octet-stream")
{
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Disposition: attachment; filename = $filename");
    header("Content-Length: " . filesize($pathto . $filename));
    header("Content-Type: $mimetype");
    echo file_get_contents($pathto . $filename);
}

方法二:

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 替换str_replace的使用方法,支持多个替换

下一篇:PHP 如何开启错误提示显示所有错误?