我是Drupal/web开发的新手,我一直在尝试创建一个模块来添加文件上传菜单。一旦上传了文件,就会进行处理,并在完成处理后显示一条消息。一切运行良好,但我想添加一个处理进度栏/从瓷砖提交按钮被选中时,最后的输出显示。我对如何实现这一点一无所知。任何帮助都是非常感谢的。
下面是我使用的代码的一部分:
//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
"),
"#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);
}从代码中可以看到,我在上传时处理文件,并在处理后显示输出消息。我想添加一个throbber/processing-从提交时间选择到输出显示时间的进度条,在文件被处理之后。我怎样才能做到这一点?再次,请理解,我是新的网页开发/Drupal,并没有非常熟练的术语/命令在他们使用。
发布于 2020-07-05 14:35:57
将文件更改为manager_file并使用属性#progress_indicator (默认情况下已经设置好了,因此不必添加它)。
https://api.drupal.org/api/drupal/developer%21topics%21forms_api接口_Cence.html/7.x#托管_文件
https://drupal.stackexchange.com/questions/295052
复制相似问题