Two upload fields (PDF & image), one saving in wrong folder

edited July 2014 in Bug Reports
If I try to upload a PDF and image at the same time, the image gets saved in the PDF folder instead of images. If I do them one at a time, they get saved in the correct folders. I tried getting rid of the on_after_post method to see if that was the issue, but it wasn't.

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Newspapers_model extends Base_module_model { public $filters = array('volume', 'issue'); public $required = array('volume', 'issue', 'published_date'); function __construct() { parent::__construct('newspapers'); } function list_items($limit = NULL, $offset = NULL, $col = 'published_date', $order = 'desc', $just_count = FALSE) { $this->db->select('id, volume, issue, published_date, published', FALSE); $data = parent::list_items($limit, $offset, $col, $order, $just_count); return $data; } function form_fields($values = array(), $related = array()) { $fields = parent::form_fields($values, $related); // Custom form code here. $fields['newspaper_pdf'] = array('ignore_representative' => TRUE, 'disabled' => TRUE); $fields['newspaper_pdf_upload'] = array('type' => 'file', 'file_name' => '{new_pdf_file_name}', 'folder' => 'pdf/newspapers/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 4); $fields['thumbnail_image'] = array('ignore_representative' => TRUE, 'disabled' => TRUE); $fields['thumbnail_image_upload'] = array('type' => 'file', 'file_name' => '{new_image_file_name}', 'folder' => 'images/newspapers/', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE, 'order' => 5); return $fields; } function on_before_post($values) { $_POST['new_pdf_file_name'] = url_title(date('Y-m-d', strtotime($_POST['published_date'])), 'dash', TRUE); $_POST['new_image_file_name'] = url_title(date('Y-m-d', strtotime($_POST['published_date'])), 'dash', TRUE); 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']) && $data['file_ext'] != '.pdf') { $config = array(); $config['source_image'] = $data['full_path']; $config['create_thumb'] = FALSE; $config['width'] = 305; $config['height'] = 475; $config['maintain_ratio'] = FALSE; $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('newspapers/'.$data->thumbnail_image, 'images'); $files[] = assets_server_path('newspapers/'.$data->newspaper_pdf, 'pdf'); foreach($files as $file) { if (file_exists($file)) { @unlink($file); } } } } class Newspaper_model extends Base_module_record { public function get_pdf_path() { return pdf_path('newspapers/'.$this->newspaper_pdf); } public function get_image_path() { return img_path('newspapers/'.$this->thumbnail_image); } }

Comments

Sign In or Register to comment.