Changing file upload path from on_before_validate or on_before_save hooks
Hi All
I am accepting multiple file types to one of my models as well as requesting the user to select from a list the category the file should be associated with. Based on the category that the user selects I need the upload path for the file to differ. Inside the form fields method I don't know what the user has/will select and therefore have to default the upload path. Is there a way to change the upload path of a file element from the on_before_validate or on_before_save hooks?
Thanks
Tim.
Comments
$fields['my_file'] = array('type' => 'file', 'folder' => 'images/{category_id}/');
$_POST['category_id'] = $_POST['item_type'];
Would you be able to help me on this?
Thanks T.
$upload_path = assets_server_path('/{category_id}/', 'media'); --Note the placeholder here
$fields['item_file_name'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'display_preview' => TRUE, 'multiple' => FALSE);
When I go to the edit screen the image preview tries to display the image with this URL:
assets/media/%7Bcategory_id%7D//Screen_Shot_2015-04-20_at_210340.png --Note the %7Bcategory_id%7D part should have been replaced with the category.
$fields['item_file_name'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'display_preview' => TRUE, 'multiple' => FALSE, 'replace_values' => $values);
Also, what version are you using. We just rolled out 1.3 this week and it had several improvements in that arena and may fix your problem.