PHP文件下载

PHP文件下载

//两种下载方式 一种header 另外一种file_put_contents
header("Content-type: text/html; charset=utf-8");
$filename=$_GET['filename'];
if(!isset($_GET['type'])){
header('content-disposition:attachment;filename='.basename($filename));
header('content-length:'.filesize($filename));
readfile($filename);
}else{
$content=file_get_contents($filename);
$path='./put';
if(!file_exists($path)){
mkdir($path,0777,true);
chomd($path,0777);
}
$save_path='./put/'.basename($filename);

if(file_put_contents($save_path,$content)) echo basename($filename).'下载成功';

}

你可能感兴趣的:(PHP文件下载)