2

How can I add a progress bar to my Managed File form field? Here's my field code:

    $form['file'] = array(
  '#type' => 'managed_file',
  '#title' => t('Logo image'),
  '#description' => t('Replace/upload a new logo for this sponsor.'),
  '#upload_location' => 'public://',
  '#upload_validators' => array(
    'file_validate_extensions' => array('gif png jpg jpeg'),
  ),      
);

I have searched for a while now, and the closest info I could find was this post but I can't quite figure out how I can add the AJAX to make this happen. Any pointers would be appreciated!

1 Answer 1

6

managed_file fapi elements are already progress bar capable by default.

managed_file

Description: Provides a complete ajax/progress aware widget for uploading a file and saving it to the {file_managed} table.

By default a simple upload button is provided for choosing the file to upload. Once a file has been chosen it can be explicitly uploaded via the "Upload" button. The upload is via AJAX and a progress meter is displayed. ....

Non-standard form element properties:

#progress_indicator: options are 'none', 'bar', and 'throbber', default is 'throbber'. #progress_message: (string) Progress message to display along with progress meter while a file is being uploaded. Defaults to NULL.

It may be possible that your server doesn't support file progress, in which case you should check and verify if the server settings are correct.

More info:

4
  • awesome answer, has all the useful info.
    – tenken
    Commented Jul 10, 2013 at 2:32
  • 1
    @David - I got the bar to show up but it seems to freeze at the beginning (showing just a bit of blue) instead of "filling in" as the file uploads... any ideas why it would do that? I'm uploading a 100MB file but the bar has been frozen in same "initial" spot for almost 20 minutes, yet the browser is still indicating the upload is progressing Commented Jul 10, 2013 at 5:41
  • Looks like it's my server problem. I'm looking into the more info links at the end of your answer. Thanks. Commented Jul 10, 2013 at 18:42
  • @David, I installed the PECL Uploadprogress (the second link in your answer) and that solved the issue, now it works like a charm! Commented Jul 15, 2013 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.