0

I am new to Drupal/web development and I have been trying to create a module to add files upload menu. Once the files are uploaded, they undergo processing and a message is displayed upon completion of the process. Everything works well but I would like to add a processing progress bar/throbber from the tile Submit button is selected to when the final output is displayed. I am clueless on how to implement this. Any help is appreciated

Here's part of the code I used:

//Before this part of the code, there is function to create Menu ($items[])
function g_p_proc_form($form, &$form_state, $values) {
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['filter'] = array (
        "#type" => "fieldset",
        "#title" => t("File Process <BR> "),
        "#collapsible" => TRUE,
    );
  // without this attribute, upload may fail on submit
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['filter']['file'] = array(
        // '#title' => t('File processing'),
        '#type'  => 'file',
        '#name' => 'files[]',
        '#description' => t('Select Submit to start processing the file'),
        '#type'  => 'file'),
        '#upload_location' => 'public://',
        '#attributes' => array('multiple' => 'multiple'),
    );

    $form['filter']['submit_upload'] = array(
        '#type'  =>  'submit', 
        '#value' =>  t('Submit'),

    );


    // drupal_set_message(t("in fn"));

    return $form;
}

function g_p_proc_form_submit($form, &$form_state) {
    try{
        $number_file = count($_FILES['files']['name']);
        $f_name = array();
        for ($i=0; $i<$number_file;$i++)
        {
            $file = file_save_upload($i, array('file_validate_extensions' => array('pdf PDF')), 'public://', FILE_EXISTS_REPLACE);
            $f_name[] = $_FILES['files']['name'][$i]; //[]
        }
            }catch (Exception $error){
        echo 'Exception: ',  $error->getMessage(), "\n";
    }
    $n_f = count($f_name);
    drupal_set_message(t('Number of files: !n_f', array('!number_f'=>$n_f)));
    $fn_name = 'g_p';
    $fn_call = $fn_name($f_name);
function g_p($f_name=array()){
    $curr_l = getcwd();
    chdir('My file processing PHP script location ');
    $n_f = count($f_name);
    $shell_command = shell_exec("file_processing_php_script_name.php");
    //header("Location: "Current file processing module menu site"); //Commented out
    drupal_set_message($shell_command);
    chdir($curr_l);
}
    

As it can be seen from the code, I process the files upon upload and display the output message after processing. I would like to add a throbber/processing-progress bar from the time Submit is selected to the time the output is displayed, after the files are processed. How can I achieve this? Again, please understand that I am new to web development/Drupal and am not very proficient in terms/commands used in them.

2
0

Change from file to manager_file and use property #progress_indicator (by default is already set so you won't have to add it).

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#managed_file

1
  • Thank you for the answer, I've tried this before and this doesn't work well for me. It doesn't allow multiple file upload simultaneously, also, it adds Upload button in addition to the Submit button and when the upload button is selected all it does is take me to the page with file name and remove button next to the name, it doesn't process and display final output for some reason. – user12824882 Jul 5 '20 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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