2014-03-06 144 views
0

如何顯示jQuery的文件上傳名稱多文件上傳插件v1.48?如何顯示jQuery的文件上傳名稱多文件上傳插件

用戶上傳文件後,有沒有辦法顯示他們已經上傳文件,在配置文件下?

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. 

回答

0

您必須合併這個$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)); 
} 
+0

嗨,應該使用哪個變量來提取文件名? $ content。='
Download Document #' . ($y+1) . ''; }這是我正在使用的代碼,但它將文本鏈接顯示爲下載文檔。有沒有辦法將固定下載文檔#更改爲顯示實際文件名的文本? – user2987446

+0

難道你不能使用$ documents ['name'] [$ key]? – dikirill

0

如果你想顯示上傳的文件上傳,你可以很容易地在JQuery中使用jQuery的上傳

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

如果你有多個文件所提供的fileuploaddone回調處理它,你需要遍歷data['result']['files']數組。

相關問題