It looks like you're new here. If you want to get involved, click one of these buttons!
function form_fields($values = array())
{
function form_fields($values = array())
{
$fields = parent::form_fields($values);
// to limit the image folder to just the projects folder for selection
$fields['image']['class'] = 'asset_select images/partners';
//$fields['description']['class'] = 'wysiwyg';
// put all project images into a projects subfolder
$fields['image_upload']['upload_path'] = assets_server_path('partners', 'images');
// fix the preview by adding projects in front of the image path since we are saving it in a subfolder
if (!empty($values['image']))
{
$fields['image_upload']['before_html'] = '<div class="img_display"><img src="'.img_path('partners/'.$values['image']).'" style="float: right;"/></div>';
}
return $fields;
}
function on_after_post($values)
{
$CI =& get_instance();
$CI->load->library('image_lib');
// create the thumbnail if an image is uploaded
if (!empty($CI->upload))
{
$data = $CI->upload->data();
if (!empty($data['full_path']))
{
$thumb_img = assets_server_path('partners/'.$this->thumb_name($data['file_name']), 'images');
// resize to proper dimensions
$config = array();
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = FALSE;
//$config['new_image'] = $thumb_img;
$config['width'] = 240;
$config['height'] = 140;
$config['master_dim'] = 'auto';
$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());
}
// create thumb
$config = array();
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = TRUE;
$config['new_image'] = $thumb_img;
$config['width'] = 300;
$config['height'] = 183;
$config['master_dim'] = 'auto';
$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;
}
// delete the images as well
function on_before_delete($where)
{
$id = $this->_determine_key_field_value($where);
$data = $this->find_by_key($id);
$files[] = assets_server_path('partners/'.$data->image, 'images');
$files[] = assets_server_path('partners/'.$this->thumb_name($data->image), 'images');
foreach($files as $file)
{
if (file_exists($file))
{
@unlink($file);
}
}
}
function thumb_name($image)
{
return preg_replace('#(.+)(\.jpg|\.png)#U', '$1_thumb$2', $image);
}
}
Comments
$fields['image']['class'] = 'asset_select images/partners';
Try:
$fields['image']['folder'] = 'images/partners';