It looks like you're new here. If you want to get involved, click one of these buttons!
CREATE TABLE IF NOT EXISTS `uploaded_files` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR (255) NOT NULL,
`filename` VARCHAR (255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `levels` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR (255) NOT NULL,
`rank` TINYINT NOT NULL,
`file_id` INT (11) NOT NULL,
`chantier_id` INT(11) NOT NULL,
`active` ENUM('yes', 'no') NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Comments
... $fields['image'] = array('type' => 'file', 'folder' => 'uploads'); // assets/uploads must be writable ...
More on that field type can be found here:
http://docs.getfuelcms.com/general/forms#file
Then, you'll need to add an on_after_post hook to your levels_model that will save the image information to the uploaded_files table. The uploaded file information can be accessed from the upload_data model property. This property holds an array of all the uploaded image information returned from CI's File upload class (see the array of information at the bottom of this page https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html).
Below is a pretty rough example to give you an idea (didn't test it out):
function on_after_post($values){ $CI =& get_instance(); $CI->load->model('upload_files_model'); foreach($this->upload_data as $data) { $save['name'] = $data['file_name']; // not sure what the name value is $save['file_name'] = $data['file_name']; $id = $CI->upload_files_model->save($save); } $values['file_id'] = $id; $this->save($values); return $values; }
More on hooks can be found here:
http://docs.getfuelcms.com/general/models#hooks
You may also want to add "uploads" => "uploads/" to the "$config['assets_folders']" found in the fuel/application/config/asset.php file
I implemented that like :
public function on_after_post($values) { $CI =& get_instance(); $CI->load->model('upload_files_model'); $this->load->library('uploader'); foreach($this->upload_data as $data) { $save['filename'] = $data['file_name']; // not sure what the name value is $save['name'] = random_string('unique') . '' . date('Ymd') . '' . $data['file_name'] ; $id = $CI->upload_files_model->save($save); rename( assets_server_path('uploads/') . '' . $save['filename'] . '' , assets_server_path('uploads/') . '' . $save['name'] . '' ); } $values['file_id'] = $id; $this->save($values); return $values; }
I there better way to do that?
http://docs.getfuelcms.com/general/forms#file