我是一名新的PHP开发人员,我一直在编写示例codeigniter程序文件上传。 文件在文件夹中成功上传,但错误即将发生。如何解决.. 控制器 //有错误,我们必须删除上传的文件
if ($is_file_error) {
if ($file) {
$file = './uploads/' . $file['file_name'];
if (file_exists($file)) {
unlink($file);
}
}
}
if (!$is_file_error) {
//save the file info in the database
$resp = $this->file->save_file_info($file);
if ($resp === TRUE) {
$this->handle_success('File was successfully uploaded.');
} else {
//if file info save in database was not successful then delete from the destination folder
$file = './upload/' . $file['file_name'];
if (file_exists($file)) {
unlink($file);
}
$this->handle_error('Error while saving file info to Database.');
}
}
答案 0 :(得分:0)
您的$ this->文件不包含文件对象,将其置于if条件中,然后在其上调用save_file_info($ file)。
if( $this->file )
{
$resp = $this->file->save_file_info($file);
}
else
{
$this->handle_error('File is not uploaded properly!, please try again.');
}