【发布时间】:2018-01-14 00:55:27
【问题描述】:
我正在尝试为图像上传验证文件上传,但它没有像其他字段一样获得验证。我正在使用Form_Validation.php 流程进行验证。
图片上传数组:
array(
'field'=>'image',
'label' => 'Image',
'rules' => 'required'
)
当我尝试上传图像时,它没有像需要的那样响应等。我还想为.jpg 等验证它以及“如何在不正确的文件上设置文件值,比如而不是.jpg 我们尝试上传.pdf"就像我们设置输入字段的值set_value('field name')等。
我检查了很多问题,也尝试使用调用方法,但无法修复它。
更新:
请提供代码示例的详细答案。请在示例中使用form_validation.php的方式并提供回调示例代码,以便我可以阅读/学习并进行相应的修改。
更新 2:
public function Task()
{
if ($this->form_validation->run('Sub_Admin/task') == FALSE) {
$this->data['Task'] = $this->bm->get_usr();
$data['title'] = "Add New Task";
$this->load->view('Subadmin/header',$data);
$this->load->view('Subadmin/nav');
$this->load->view('Subadmin/sidebar');
$this->load->view('Subadmin/task', $this->data);
$this->load->view('Subadmin/footer');
}
else
{
$config['upload_path'] = './taskimages/'; //The path where the image will be save
$config['allowed_types'] = 'gif|jpg|png'; //Images extensions accepted
$config['max_size'] ='10048'; //The max size of the image in kb's
//$config['max_width'] = '1024'; //The max of the images width in px
//$config['max_height'] = '768'; //The max of the images height in px
$config['overwrite'] = FALSE; //If exists an image with the same name it will overwrite. Set to false if don't want to overwrite
$this->load->library('upload', $config); //Load the upload CI library
$this->load->initialize($config);
$this->upload->do_upload('task');
$file_info = $this->upload->data();
$file_name = $file_info['file_name'];
$data = array(
'Job_Title' => $this->input->post('jtitle'),
'Priority' => $this->input->post('jnature'),
'Assignee' => $this->input->post('assigne'),
'Employee_Name' => $this->input->post('assignto'),
'Due_Date' => $this->input->post('ddate'),
'Reminder' => $this->input->post('reminder'),
'Task_Image' => $file_name,
);
$this->bm->add_task($data);
}
}
我已经在使用 CI 上传类,但它不起作用,现在我想从 form_validation 端验证图像/文件。
【问题讨论】:
-
SO 不是编码服务(甚至不是赏金)。提供您迄今为止尝试过的内容以及您遇到的问题。
-
@msz 我已经根据你的问题更新了我的代码。
-
我认为以下答案会对您有所帮助。 Click here
标签: php validation file-upload codeigniter-3