一、思路 重复:将原有的数据存储到数组arrNo中,然后使用getField方法来实现。读取要存入的数据,检测该数据是否在arrNo中存在,使用in_array()。若存在则网页现在该数据已存在,若不存在,则写入二维数组$arr,并且把学号追加到arrNo中;
上传:再上传中先写一种方法,在HTML代码中的form表单中写入要提交的路径,用IS_GET请求,form表单为post请求,实例化上传类,设置附件上传大小,设置附件上传类型,设置附件上传根目录,设置附件上传(子)目录,然后上传文件,用if,else提示上传错误,上传成功的提示信息。
public function upload(){
if(IS_GET){
$this->display();
}
$upload=new \Think\Upload();
$upload->maxSize=0;//文件大小
$upload->exts=array('csv');
$upload->rootPath='./Public/Upload/';
$upload->savePath='';
//上传文件
$info=$upload->upload();
if(!$info){
$this->error($upload->getError());
}else{
$this->import($upload->rootPath.$info['file']['savepath'].$info['file']['savename']);
// $this->success('上传成功!');
}
}
下载:在路径中写一个log.txt为下载文件名,写下载文件存放目录
public function download(){
$file_name=$file;
$file_dir="./Public/Download/";
if(!file_exists($file_dir . $file_name)){
echo "文件找不到";
exit();
}else{
$file=fopen($file_dir.$file_name, "r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Accept-Length:" . filesize ($file_dir . $file_name));
Header("Content-Disposition:attachment;filename=".$file_name);
echo fread($file, filesize($file_dir.$file_name));
exit();
}
}