abstract:class product extends Common{public funtion index(){//渲染首頁模版return $this->fetch();}public function add(){//渲染產(chǎn)品添加界面return $this->fetch();}public function upload(){//獲取上傳圖片信息$file = Request::file
class product extends Common{
public funtion index(){
//渲染首頁模版
return $this->fetch();
}
public function add(){
//渲染產(chǎn)品添加界面
return $this->fetch();
}
public function upload(){
//獲取上傳圖片信息
$file = Request::file('img');
//驗(yàn)證圖片格式并上傳至指定目錄
if($info = $file->validate(['ext']=>'jpg,jpeg,gif')->move('upload')){
return json(['errno'=>0,'data'=>['/upload/'.$info->getSaveName()]]);
}else{
return $file->getError();
}
}
public function DoAdd(){
//獲取提交數(shù)據(jù)
$data= Request::param();
$title=$data['title'];
$info =ProductModel::where('title',$title)->find();
if($info == true){
return ['res'=>1,'msg'=>'產(chǎn)品標(biāo)題重復(fù)'];
$data['time']=time();
$data['username']=Session::get('username');
$product= new ProductModel();
if($product->save($data)){
return['res'=>1,'msg'=>'添加信息成功!'];
}else{
return ['res'=>0,'msg'=>'添加信息失敗!'];
}
}
}
public function edit(){
$proId= Request::param('id');
$product =ProductModel::get($proId);
//賦值給模版
$this->view->product=$product;
//渲染產(chǎn)品編輯頁面
return $this->fetch();
}
public function DoEdit(){
$data =Request::param();
$product =new ProductModel();
$data['time']=time();
$data['username']=Session::get('username');
$info= $product->save(
[
'title'=>$data['title'],
'desc'=>$data['desc'],
'content'=>$data['content'],
'once'=>$data['once'],
'over_night'=>$data['over_night'],
'time'=>$data['time'],
'username'=>$data['username'],
],['id'=>$data['id']]
);
if($info){
return ['res'=>1,'msg'=>'更新成功!'];
}else{
return ['res'=>0,'msg'=>'更新失??!'];
}
}
pupublic funtion del(){
//獲取產(chǎn)品ID
$proId = Request::param('id');
$product = new ProductModel();
if($product->destroy($proId)){
return ['res'=>1,'msg'=>'刪除成功!'];
}
}
}
Correcting teacher:西門大官人Correction time:2019-05-05 10:09:35
Teacher's summary:思考一下,如果把一個.mp3的文件的擴(kuò)展名改成了.jpg,是否可以通過你的驗(yàn)證呢?