php 文件下载

<?php
	$document=$db->getRow("SELECT  file_name,file_url  FROM  documents  WHERE id='".$_REQUEST['id']."'");
	
	$fileUrl = $document['file_url']; 
	$fileName = $document['file_name']; 
	/**
	 * 文件下载
	 * @parameter  $urlUrl             文件的url地址  例如'./index.html'
	 * @parameter  $fileName  下载下来新的文件名字  例如'测试1'
	 */
	if (file_exists($urlUrl)) { 
		header('Content-Description: File Transfer'); 
		header('Content-Type: application/octet-stream'); 
		header('Content-Disposition: attachment; filename='.$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($file)); 
		ob_clean(); 
		flush(); 
		readfile($file); 
		exit; 
	}

>

猜你喜欢

转载自blog.csdn.net/JXL9910/article/details/83214187