<?php
/*
*下载浏览器可以打开的文件类型。
*
*下载链接传递过程中遇到#等特殊字符
*传递的值会不全,需要先替换为其他
*字符后再转换回来
*/
include("../config.php");
$sql="SELECT * FROM `wxwc_file`";
$res=mysql_query($sql);
if (isset($_GET['path'])) {
$path=$_GET['path'];
$path=str_replace("?", "#", $path);
$url = iconv('utf-8','gbk',$path);
$sql1="SELECT * FROM `wxwc_file` where file_path='".$path."'";
$res1=mysql_query($sql1);
$row1=mysql_fetch_row($res1);
$fileName=$row1[1];
$file = fopen($fileName,"r"); // 打开文件
// 输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($path));
Header("Content-Disposition: attachment; filename=" . $fileName);
// 输出文件内容
echo fread($file,filesize($path));
fclose($file);
exit();
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div class="main">
<div class="info">
<input type="submit" name="submit" οnclick="window.location.href='?path=你的文件名(包含后缀名)'" value="下载">
</div>
</body>
</html>