这是上传函数和路径class FileController extends Controller{
public function upload(){
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 0 ;// 附件上传大小
$upload->exts = array('jpg','gif','png','jpeg');// 附件上传类型
$upload->rootPath = './ueditor/php/upload/image/'; // 附件上传目录
$upload->saveName = 'com_create_guid';// 采用GUID序列命名
$info=$upload->upload();
if(!$info){
$this->error($upload->getError());
}else{
foreach($info as $file){
$this->success($file['savepath'].$file['savename']."上传成功!",'',3);
}
}
$model = M('File');
$data['savename'] = $info[0]['savename'];
$data['create_time'] = NOW_TIME;
$model->add($data);
}这是download.html,需要实现的视图<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>下载</title>
<link href="__PUBLIC__/css/download.css" rel="stylesheet" type="text/css">
</head>
<body>
<form method="get">
<table>
<tr>
<td><a href="__APP__/Home/File/download/id/{$id}">下载</a></td>
</tr>
</table>
</form>
</body>
</html>如何在这个视图里实现选择下载哪个文件,网上大多都是点击之后下载预定好的文件,这个能选择吗?
2 回答
李罗奥
TA贡献4条经验 获得超5个赞
这是download
public function download(){ $uploadpath='./ueditor/php/upload/image/';//设置文件上传路径 $file=M('File'); $wo=$_GET['savename']; $result= $file->find($wo);//根据id查询到文件信息 if($result==false) //如果查询不到文件信息 { $this->error('下载失败!', '', 1); }else{ $savename=$file->savename;//文件保存名 $showname=$file->truename;//文件原名 $filename=$uploadpath.$savename;//完整文件名(路径加名字) import('ORG.Net.Http'); Http::download($filename,$showname); } }
添加回答
举报
0/150
提交
取消