[英]CodeIgniter - Combine form validation and file upload
我想用上传文件的标题和摘要的一些字段创建文件上传。 我也看过这个问题,但我完全不了解它。
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.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.