【问题标题】:How to show the file upload name for jQuery Multiple File Upload Plugin如何显示 jQuery 多文件上传插件的文件上传名称
【发布时间】:2014-03-06 17:47:30
【问题描述】:

jQuery Multiple File Upload Plugin v1.48如何显示文件上传名称?

用户上传文件后,有没有办法在配置文件下显示他们上传的文件?

1.if ( isset($_FILES['tb-documents']) ) {        
  $documents = $_FILES['tb-documents'];
  foreach ( $documents['name'] as $key => $value ) {
   if ( $documents['name'][$key]) {
    $document = array(
     'name' => $documents['name'][$key],
     'type' => $documents['type'][$key],
     'tmp_name' => $documents['tmp_name'][$key],
     'error' => $documents['error'][$key],
     'size' => $documents['size'][$key]       
     );
        $status = wp_handle_upload($document, array('test_form' => false));

    if( !isset($status['error']) ) {
     $uploads = wp_upload_dir();
     add_user_meta($user->ID, 'tb-documents', $uploads['url'].'/'.basename($status['file']));
    }                 
   }

  }
 }

上传在用户个人资料上运行良好。但是,我想提取他们上传的文件名,并将所有上传的文件名显示给他们。

我应该使用哪个变量?

1.I tried this, $content .= '.$documents['name']'; but it doesn't work. It shows syntax error.

【问题讨论】:

    标签: php jquery file-upload


    【解决方案1】:

    您必须组合来自此$documents['name'][$key] 的结果并将其显示给用户。 例如:

    if (isset($_FILES['tb-documents'])) {
        $uploadedFiles = array();
        $documents = $_FILES['tb-documents'];
        foreach ($documents['name'] as $key => $value) {
            if ($documents['name'][$key]) {
                $document = array(
                        'name' => $documents['name'][$key],
                        'type' => $documents['type'][$key],
                        'tmp_name' => $documents['tmp_name'][$key],
                        'error' => $documents['error'][$key],
                        'size' => $documents['size'][$key]
                );
                $status = wp_handle_upload($document, array('test_form' => false));
    
                if (!isset($status['error'])) {
                    $uploads = wp_upload_dir();
                    add_user_meta($user->ID, 'tb-documents', $uploads['url'] . '/' . basename($status['file']));
                    $uploadedFiles[] = $documents['name'][$key];
                }
            }   
        }
    
        var_dump(implode(", ", $uploadedFiles));
    }
    

    【讨论】:

    • 嗨,我应该使用哪个变量来提取文件名? $content .= '
      下载文档#' . ($y+1) 。 '';这是我正在使用的代码,但它将文本链接显示为下载文档。有没有办法将固定的下载文档#更改为显示实际文件名的文本?
    • 你不能使用 $documents['name'][$key] 吗?
    【解决方案2】:

    如果你想将上传的文件显示给上传者,你可以使用jQuery上传者提供的fileuploaddone回调在JQuery中轻松处理

    $('#fileupload')
        .bind('fileuploaddone', function (e, data) {
                console.log( data['result']['files'][0]['name'] );
                console.log( data['result']['files'][0]['url'] );
            });
    

    如果你有多个文件,你需要循环data['result']['files']数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 2019-11-09
      • 1970-01-01
      • 2013-12-19
      • 2012-01-30
      相关资源
      最近更新 更多