アップロードしたばかりのファイルの名前を取得し、それを index() 関数に渡してデータベースに挿入する方法を知っている人はいますか?
これは codeigniter で書かれており、これが私のフォーム コントローラーのコードです。
ありがとう。
public function index() {
$this->load->library('form_validation');
$this->form_validation->set_rules('nominee', 'Nominee', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[self_nominees.email]');
$this->form_validation->set_rules('location', 'Location', 'required');
$this->form_validation->set_rules('category', 'Category', 'required');
$this->form_validation->set_rules('description', 'Description', 'required');
$this->form_validation->set_rules('imageupload', 'Image Upload', 'callback__image_upload');
$this->form_validation->set_rules('videoupload', 'Video Upload', 'callback__video_upload');
if ($this->form_validation->run() == FALSE)
{
//Load the form
$this->template('form.php');
}
else
{
//Run code to add into the database
$formdata = $this->input->post(NULL, TRUE); // this prevent from XSS attacks
$this->load->model('users');
$this->users->self_nominate($formdata['nominee'], $formdata['email'], $formdata['location'], $formdata['category'], $formdata['description'], 'image', 'video');
//Load the thankyou page
$this->template('thankyou.php');
}
}
/*----------------------------------------------------------------
Image Upload Function
----------------------------------------------------------------*/
function _image_upload()
{
$this->load->library('upload');
// Check if there was a file uploaded
if (!empty($_FILES['imageupload']['name']))
{
// Specify configuration for File 1
$config['upload_path'] = 'uploads/images';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
// Initialize config for File 1
$this->upload->initialize($config);
// Upload file 1
if ($this->upload->do_upload('imageupload'))
{
$data = $this->upload->data();
return true;
}
else
{
$imageerrors = $this->upload->display_errors();
$this->form_validation->set_message('_image_upload', $imageerrors);
return false;
}
}
}