It looks like you're new here. If you want to get involved, click one of these buttons!
function asset_custom_path_upload(&$fields,&$values, $field_name, $custom_path, $field_type='images'){
global $__FUEL_CUSTOM_IMAGE_ORDER;
if(empty($__FUEL_CUSTOM_IMAGE_ORDER)) $__FUEL_CUSTOM_IMAGE_ORDER = 100;
$config_asset = array(
'class'=>'asset_select '.$field_type.'/' . $custom_path,
'order'=> $__FUEL_CUSTOM_IMAGE_ORDER++
);
$config_upload = array(
'type' => 'file',
'label'=> 'OR Upload a new image',
'upload_path' => assets_server_path($custom_path, $field_type),
'overwrite' => TRUE,
'order'=> $__FUEL_CUSTOM_IMAGE_ORDER++
);
$img = '<div class="img_display"><img src="'.assets_path().$field_type.'/%s" style="float: right;"/></div>';
$config_upload['before_html'] = (!empty($values[$field_name]) ? sprintf($img, $custom_path . $values[$field_name]) : "");
$fields[$field_name] = $config_asset;
$fields[$field_name . '_upload'] = $config_upload;
}
Comments
If anyone else is interested in using this function, it allows you to set a custom upload path and asset path with one line. Add the above function to your model, and call it in form_fields using
$this->asset_custom_path_upload( $fields, $values, // Reference to fields & values arrays "field_name", // DB column name "path/to/use/", // With trailing slash "images" // [optional] images,pdf,etc );
It will then place the specified field uploaders at the end of your form and sandbox the user in a specific directory.
Thanks "admin" (David right?)