Custom image upload path (_image and _image_upload)

edited February 2011 in Modules
I've built a function that allows me to set a custom image path for images to upload into and for the asset selector to pull from. This goes in a model
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; }
Basically it just adds the needed field config for both the field and _upload counterpart.

My question is, how can I get the _upload field to follow directly after my _image field? It seems the the _upload fields are added after all my database fields are converted into the form. The code I have above works, it just puts the file selector at the end where I'd like it to be grouped with each image field.

Comments

  • edited 2:01PM
    There is an 'order' parameter you can set for the field which should help where it is located in the form.
  • edited 2:01PM
    Oh awesome. That works great.

    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?)
  • edited 2:01PM
    You're welcome... (and David is my name)
Sign In or Register to comment.