Teacher Zhu: When I test uploading a file whose format does not meet the requirements, the page reports an error (500 error); what's going on?
You probably haven’t reached the update method yet, come here
When uploading a file in the correct format, the prompt message is set in the controller: Upload successful! This is no problem;
But when uploading a file in the wrong format, the prompt message is Page Error 500? ??
The following is the code (same as the teacher’s):
public function update(){ //Get all request data including uploaded files: $data= $this->request->param(true); //For individual file operations, package it into a file object $file=$this->request->file('image') ; //File verification and upload: $info=$file->validate(['ext'=>'jpg,png','size'=>3000000])->move (ROOT_PATH.'public/uploads/'); if(is_null($info)){ $this->error($file->getError()); } //Perform update operation $res=banner_model::update([ ] 'image'=>$info->getSaveName(), 'link'=>$data['link' ], 'desc'=>$data['desc'], ],['id'=>$data['id']]); //Check whether the update is successful : if(is_null($res)){ $this->error('Update failed'); } $this->success('Update successful');}
Masters, please help me take a look;
It should be that the ajax code is written incorrectly, please check the code carefully. ,
You probably haven’t reached the update method yet, come here
When uploading a file in the correct format, the prompt message is set in the controller: Upload successful! This is no problem;
But when uploading a file in the wrong format, the prompt message is Page Error 500? ??
The following is the code (same as the teacher’s):
public function update(){
//Get all request data including uploaded files:
$data= $this->request->param(true);
//For individual file operations, package it into a file object
$file=$this->request->file('image') ;
//File verification and upload:
$info=$file->validate(['ext'=>'jpg,png','size'=>3000000])->move (ROOT_PATH.'public/uploads/');
if(is_null($info)){
$this->error($file->getError());
}
//Perform update operation
$res=banner_model::update([
] 'image'=>$info->getSaveName(),
'link'=>$data['link' ],
'desc'=>$data['desc'],
],['id'=>$data['id']]);
//Check whether the update is successful :
if(is_null($res)){
$this->error('Update failed');
}
$this->success('Update successful');
}
Masters, please help me take a look;
It should be that the ajax code is written incorrectly, please check the code carefully. ,