form_fields config confusion
I want to configure a form_fields function such that it can upload an image (a screenshot) and videos (perhaps of several types, eg m4v, ogg, webm) in one submit. However, I'm a bit confused as how the various configuration arrays enable this. It seems there are a number of files that might require editing outside of the model I'm concerned with - eg in the application/config folder I might need to edit: mimes.php, MY_fuel.php and asset.php. Also, I'm not clear how the "assets_server_path" function really works. For example, I can upload images OK with only 1 argument ( assets_server_path('_uploads/photos/') ). If I can determine the path completely with that, why is there a 2nd argument that seems to determine the parent folder ( eg assets_server_path('_uploads/photos/', 'images') )? What is the relationship between assets_server_path() and editable_asset_filetypes, or, how do you determine what extensions are permitted by the upload? How are the keys of $config['assets_folders'] usable, and do they have a bearing on "assets_server_path"? I should add that I've succeeded with uploading images, and video, but not adequately determining which video file types are permitted, and where. I can upload mp4 extensions, but not m4v, even thought the configuration for both seems in hand!
I've tried to discover the answers for myself from the forums and documentation, but I can't seem to get a cohesive picture!
Comments
Additionally, if you want to add a folder like "_uploads" to your assets, you will need to add that to your "asset_folders" asset config parameter and make it writable (which I imagine you've already done).
With regards to the second parameter on the assets_server_path() function, it grabs the path for that asset type from the config. If you don't change the structure of your asset directory, then you don't need to use it.
Additionally, there is a "sanitize_images" property you can set on your module in MY_fuel_modules.php that should be probably set to FALSE, since it uses the xss_clean function which can give you false positives when uploading certain file types.
Most all the logic for this happens in the fuel/modules/fuel/controllers/module.php in the _process_uploads() method at the bottom. In particular around line 1441 where it sets the $config['allowed_types'] configuration parameter for CI's File Upload class.
I hope that helps.
I've set up my asset filetypes like so, in config/MY_fuel.php:
$config['editable_asset_filetypes'] = array( 'images' => 'jpg|jpeg|jpe|gif', 'pdf' => 'pdf', );
In one of my simple module forms, I want to be able to upload images, so I use an _upload form field with an $upload_path set to "images". Like so:
$upload_path = assets_server_path('groups/', 'images'); $fields['image_upload'] = array('type' => 'file', 'label' => 'Mylabel', 'upload_path' => $upload_path, 'overwrite' => TRUE, 'filename' => '{groups_id}')
I can upload JPEGs just fine, and if I try to upload a PNG, it fails, as it should. However, the form will accept and process a PDF. Is this normal behavior?
I would like to restrict this particular form to uploading only JPEGs. I've tried passing an 'accept' parameter in my image_upload field, to no avail.
Incidently, if I change 'images' to, say, 'bubbles' in the 'editable_asset_filetypes' array, JPEGs are still uploadable in the images form field. It seems that if a media type is listed in 'editable_asset_filetypes', regardless of what folder it is assigned to, it will be uploadable.
Am I missing something very obvious?
$config['editable_asset_filetypes'] = array( 'images' => 'jpg|jpeg|jpe|gif', 'images/groups' => 'jpg|jpeg|jpe|gif', 'pdf' => 'pdf', );
By specifying, for example...
... 'beeblebrox' => 'jpg|jpeg|jpe|gif', 'prefect' => 'pdf', ...
... in editable_asset_filetypes, I can upload jpgs, gifs and pdfs in any of my upload form fields, regardless of what parameters I use for "assets_server_path".
So all the allowed filetypes are taken into account but they are not specific to any upload folders.
As for debugging, the value of "$config['allowed_types']", I don't really know how to go about that, since I'm actually a designer and not a programmer. If you or anyone else can point me in the right direction, I'll be happy to work it out and get back to you.
Thanks
$config['editable_asset_filetypes'] = array( 'images' => 'jpg|jpeg|jpe|gif|png', 'pdf' => 'pdf', 'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|mp4|m4a|m4v|flv|swf|aiff|ogv|webm|mpeg|mp2', '_uploads/videos' => 'jpg|jpeg|jpe|png|gif|mov|mp3|mp4|m4a|m4v|flv|mpg|swf|aiff|ogv|webm|mpeg|mp2', '_uploads/documents' => 'doc|docx|xls|xlsx|pdf|rtf|txt|xml' );
so in theory I should only be able to upload the values for '_uploads/videos' (this is the defined assets_server_path for the module). But in fact I can upload a PDF fine, and printing out the 'allowed_types' from the module.php controller's _process_uploads() method shows 'pdf' when I do so.
If I remove all instances of 'pdf' from my editable_asset_filetypes then the upload is refused, but if pdf is included in any key, the upload goes ahead OK.
So I can confirm maxbel's issue with v.0.93.
https://github.com/daylightstudio/FUEL-CMS
To fix in .93, try adding the following to the fuel/modules/fuel/controllers/module.php around line 1439 right before "$config['remove_spaces'] = TRUE;"
$upload_folder = trim(str_replace(assets_server_path(), '', $config['upload_path']), '/'); $config['allowed_types'] = ($this->assets_model->get_dir_filetype($upload_folder)) ? $this->assets_model->get_dir_filetype($upload_folder) : 'jpg|jpeg|png|gif';
The folders names (e.g. images/groups) should not have trailing slashes.
Can u help me.