Commit 29a8f5d9 by Bojan Borovcanin

Controller changed to upload image files to database

parent d1168d65
Showing with 16 additions and 2 deletions
......@@ -58,7 +58,6 @@ class Activity extends CI_Controller{
$this->form_validation->set_rules('title','Title','required|max_length[30]');
$this->form_validation->set_rules('description','Description','required|max_length[300]');
$this->form_validation->set_rules('datetime','DateTime','required');
$this->form_validation->set_rules('inpImage','Image','required');
$this->form_validation->set_rules('price','Price','required|max_length[30]');
$this->form_validation->set_rules('full_name','Full name','required|max_length[30]');
$this->form_validation->set_rules('phone_number','Phone number','required|max_length[30]');
......@@ -75,12 +74,27 @@ class Activity extends CI_Controller{
$data['title'] = $this->input->post('title');
$data['description'] = $this->input->post('description');
$data['datetime'] = $this->input->post('datetime');
$data['image'] = $this->input->post('inpImage');
$data['price'] = $this->input->post('price');
$data['full_name'] = $this->input->post('full_name');
$data['phone_number'] = $this->input->post('phone_number');
$data['email'] = $this->input->post('email');
$content;
$tmpname = $_FILES['inpImage']['tmp_name']; //The temporary filename of the file in which the uploaded file was stored on the server.
$filesize = $_FILES['inpImage']['size'];
$filetype = $_FILES['inpImage']['type'];
$allowedtypes=array("image/jpeg","image/jpg","image/png","image/gif");
if($filesize>=0){
if(in_array($filetype, $allowedtypes))
{
$fp = fopen($tmpname, 'r');
$content = fread($fp, filesize($tmpname));
$data['image'] = $content; //it adds blackslashes after each quote(double or single)
fclose($fp);
}
}
$this->Activity_model->addNewActivity($data);
$array['activities'] = $this->Activity_model->getAllActivities();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment