[英]CodeIgniter 3 - Callable Form Validation by Config file not working
[英]Codeigniter form validation for file
我正在為我的項目使用codeigniter,我需要讀取文件的內容。 所以,我需要驗證來檢查文件是否被選中。
這是我在控制器中的代碼
$this->form_validation->set_rules(
'estimation_file',
'Project Estimation File',
'required'
);
但是,在選擇文件時,它會顯示錯誤信息-必須輸入“項目估算文件”字段
在codeigniter中,您無法使用form_validation檢查二維數組或文件字段的有效性,而是可以在發布數據后進行檢查。
$this->form_validation->set_rules('validation_check','any required field','required');
if($this->form_validation->run()==FALSE)
{
// your code before posting...
}
else
{
// check the file posting
if($_FILES['estimation_file']['name']!='')
{
// if file selected or not empty
}
else
{
// if file not selected | empty | redirect
}
}
不要忘記在form字段中編寫enctype =“ multipart / form-data”,否則您的文件字段將不會傳遞二維數組的值。
<form method="post" enctype="multipart/form-data" name="upload_form" action="">
<input type="hidden" name="validation_check" value="TRUE" />
<input type="file" name="estimation_file" value="" />
<input type="submit" value="Post" />
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.