下载时重命文件
html代码
<a onclick="downnew('http://www.baidu.com/img/baidu_jgylogxo3.gif','下载图片1');">下载</a>
js代码
<script type="text/javascript">
/**
* 下载时重命名
*/
function downnew(url,title){
url = encodeURI(url);
title = encodeURI(title);
window.location.href="readfiles?url="+url+"&title="+title;
};
</script>
php 代码
public function readfiles(){
$path = $_GET['url'];
$info = pathinfo($path , PATHINFO_EXTENSION);
$file_name = $_GET['title'].'.'.$info; //这里重命名
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename='.$file_name);
ob_end_clean();
readfile($path);
exit();
}