我想创建带有一些字段的文件上传,用于上传文件的标题和摘要。我也看过这个问题,但我不完全理解。
function someform()
{
// some variables for fields
($this->form_validation->run() == FALSE)
{
}
else
{
// how to check if the file was uploaded?
}
}
您应该检查文件上传以外的所有其他字段的验证。验证成功后,检查文件。例子:
function someform()
{
// some variables for fields
($this->form_validation->run() == TRUE)
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$fileTagName = 'myfile'; // e.g <input type='file' name='myfile' />
if ($this->upload->do_upload($fileTagName))) {
//Success in validation of all fields.
}
else {
//Failed to upload file.
echo $this->upload->display_errors('', '');
}
}
else
{
//Other fields failed.
}
}