Filename Not Saving in Database for Image Upload

edited February 2017 in Modules
Since I upgraded to the newest version of Fuel, I've had trouble with uploaded images not being inserted/updated in the database. The image uploads and appears in Assets, however, the featured_image column is blank in the database and the image doesn't display in the module.

function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); $fields['slug']['type'] = 'hidden'; $fields['content']['img_folder'] = 'articles/'; $fields['keywords']['type'] = 'hidden'; $fields['featured_image'] = array('ignore_representative' => TRUE); $fields['featured_image_upload'] = array('type' => 'file', 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9); return $fields; } function on_before_post($values) { $post_date = (empty($_POST['post_date'])) ? date('Y-m-d') : $_POST['post_date']; $_POST['new_file_name'] = url_title(date('Y-m-d', strtotime($post_date)).'-'.$_POST['title'], 'dash', TRUE).'-featured'; return $values; } function on_after_post($values) { $CI =& get_instance(); $CI->load->library('image_lib'); if (!empty($CI->upload)) { $data = $CI->upload->data(); if (!empty($data['full_path'])) { $config = array(); $config['source_image'] = $data['full_path']; $config['create_thumb'] = FALSE; $config['width'] = 1024; $config['height'] = 768; $config['maintain_ratio'] = TRUE; $CI->image_lib->clear(); $CI->image_lib->initialize($config); if (!$CI->image_lib->resize()) { $this->add_error($CI->image_lib->display_errors()); } } } return $values; } function on_before_delete($where) { $id = $this->_determine_key_field_value($where); $data = $this->find_by_key($id); $files[] = assets_server_path('articles/'.$data->featured_image, 'images'); foreach($files as $file) { if (file_exists($file)) { @unlink($file); } } }
Any idea what's going on?

Comments

  • edited 4:35AM
    Are you on 1.3.2 (master) or 1.4 (develop)?
  • edited 4:35AM
    1.3.2.
  • edited 4:35AM
    Also, could you post the table schema you are using for the module?
  • edited 4:35AM
    CREATE TABLE IF NOT EXISTS `articles` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `subtitle` varchar(1020) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'This is the last part of the url string.', `author_id` tinyint(3) unsigned NOT NULL DEFAULT '0', `content` text COLLATE utf8_unicode_ci NOT NULL, `excerpt` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'A condensed version of the content. If left blank, the excerpt will automatically be created for you.', `keywords` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '15 keywords generated from the content.', `featured` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no' COMMENT 'Yes, if you want this article featured on the home page.', `featured_image` varchar(510) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Featured image must be landscape orientation, such as 1024 x 768.', `featured_caption` varchar(2550) COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Caption for the featured image.', `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'If left blank, the date will default to today.', `date_added` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `published` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes' COMMENT 'Yes, if you want this article on the website.', PRIMARY KEY (`id`), UNIQUE KEY `permalink` (`slug`), FULLTEXT KEY `keywords` (`keywords`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  • edited 4:35AM
    I would recommend removing the "featured_image_upload" field and instead replacing it with just the "featured_image" field and set display_input and display_preview to TRUE:
    $fields['featured_image'] = array('type' => 'file', 'ignore_representative' => TRUE, 'display_preview' => TRUE, 'display_input' => TRUE, 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9); // $fields['featured_image_upload'] = array('type' => 'file', 'file_name' => '{new_file_name}', 'folder' => 'images/articles/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 9);
  • edited 4:35AM
    It's working now, thanks so much!
Sign In or Register to comment.