123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace Admin\Controller;
- use Think\Controller;
- use Think\Upload;
- class ArticleController extends Controller
- {
- public function lst()
- {
- $first = D('article');
- $firsts = $first->select();
- $this->assign('firsts', $firsts);
- $this->display();
- }
- public function add()
- {
- $first = D('article');
- if (IS_POST) {
- $data = I("post.");
- $data['time'] = time();
- if ($_FILES['file']['tmp_name']!=''){
- $upload=new Upload();//实例化上传类
- $upload->maxSize= 553145728 ;//设置上传大小
- $upload->exts=array('png','jpg','gif','jpeg');//设置文件上传类型
- $upload->savePath = '/./Uploads/'; // 设置附件上传(子)目录
- $upload->rootPath='./';//上传根目录
- $upload->saveName=array('uniqid','');//上传文件的保存规则,支持数组和字符串方式定义
- $info=$upload->uploadOne($_FILES['file']);
- if (!$info){
- $this->error($upload->getError());//上传错误提示信息
- }else{
- $data['src']=$info['savepath'].$info['savename'];
- $data['name']=$_FILES['file']['name'];
- $data['rname']=$info['savename'];
- }
- }
- if ($first->create($data)) {
- if ($first->add()) {
- $this->success('新增文章成功', U('Article/lst'));
- } else {
- $this->error('新增文章失败');
- }
- } else {
- $this->error($first->getError());
- }
- return;
- }
- $this->display();
- }
- public function del()
- {
- $first = D('article');
- if ($first->delete(I('id'))) {
- $this->success("删除文章成功", U('Article/lst'));
- } else {
- $this->error('删除文章失败');
- }
- }
- public function edit(){
- header('Content-Type: text/html; charset=utf-8');
- $first=D('article');
- if(IS_POST){
- $data=I('post.');
- $data['id']=I('get.id');
- $data['time']=time();
- if ($_FILES['file']['tmp_name']!=''){
- $upload=new Upload();//实例化上传类
- $upload->maxSize= 553145728 ;//设置上传大小
- $upload->exts=array('png','jpg','gif','jpeg');//设置文件上传类型
- $upload->savePath = './Uploads/'; // 设置附件上传(子)目录
- $upload->rootPath='./';//上传根目录
- $upload->saveName=array('uniqid','');//上传文件的保存规则,支持数组和字符串方式定义
- $info=$upload->uploadOne($_FILES['file']);
- if (!$info){
- $this->error($upload->getError());//上传错误提示信息
- }else{
- $data['src']=$info['savepath'].$info['savename'];
- $data['name']=$_FILES['file']['name'];
- $data['rname']=$info['savename'];
- }
- }
- if($first->save($data)){
- $this->success('修改文章成功',U('Article/lst'));
- }else{
- $this->error('修改文章失败');
- }
- return;
- }
- $firstid['id']=I('get.id');
- $firsts=$first->find($firstid);
- // var_dump($firsts);
- $this->assign('firsts',$firsts);
- $this->display();
- }
- }
|