2015-09-18 117 views
-2

我可以通過PHP上傳具有動態路徑的文件。但我無法在動態文件夾中列出上傳的文件。也許jQuery沒有獲得動態路徑。但我該怎麼做呢?blueimp通過動態路徑獲取上傳的文件列表

感謝您的幫助

+0

'也許jQuery沒有得到動態路徑'也許。發佈您的代碼。 –

+0

這與jQuery File Upload的默認index.html完全一樣。對於上傳,我只添加隱藏的輸入。 – Hugh1024

回答

0

好吧,我得到的解決方案,我花時間在它上面。所以我的解決方案是在jQuery彈出窗口中使用iframe,並將其集成到一個自制的框架中。

步驟1:jQuery的彈出窗口

<div id="fileuploadbox" title="Add file(s)"></div> 
<script> 
function fuBox(aFolder,aId) 
{ 
    $("#fileuploadbox").dialog({ 
    autoOpen: false, 
    modal: true, 
    width: "850px", 
    }); 

    $('#fileuploadbox').html(''); 
    $('#fileuploadbox').append($('<iframe width=800 height=400 border=0 />').attr('src', 'index.php?module=fileupload&mode=client&folder='+aFolder+'&id='+aId)).dialog('open'); 

} 
</script> 

在我的情況,該文件夾位置取決於基礎文件夾和電網行的id。例如,對於文件夾= article和id = 18756,動態上載路徑爲APP_FILE_PATH/article/18756。

步驟2:IFRAME頁

iframe的頁面是一樣的blueimp jQuery的文件的上傳的的index.html。

<form id="fileupload" action="index.php" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="module" value="fileupload"> 
    <input type="hidden" name="mode" value="server"> 
    <input type="hidden" name="folder" value="<?php echo $_GET['folder'].'/'.$_GET['id']; ?>/"> 

我Concat的文件夾,並在標識一個參數,它都發送到服務器頁面。

在底部,就必須發表評論main.js,使你自己的代碼,我做到了:

<script> 
$(function() { 
    'use strict'; 

    // Initialize the jQuery File Upload widget: 
    $('#fileupload').fileupload({ 
     // Uncomment the following to send cross-domain cookies: 
     url: '?module=fileupload&mode=server&folder=<?php echo $_GET['folder']."%2f".$_GET['id']; ?>%2f' 
    }); 

    // Enable iframe cross-domain access via redirect option: 
    $('#fileupload').fileupload(
     'option', 
     'redirect', 
     window.location.href.replace(
      /\/[^\/]*$/, 
      '/cors/result.html?%s' 
     ) 
    ); 

    // Load existing files: 
    $('#fileupload').addClass('fileupload-processing'); 
    $.ajax({ 
     // Uncomment the following to send cross-domain cookies: 
     //xhrFields: {withCredentials: true}, 
     url: $('#fileupload').fileupload('option', 'url'), 
     dataType: 'json', 
     context: $('#fileupload')[0] 
    }).always(function() { 
     $(this).removeClass('fileupload-processing'); 
    }).done(function (result) { 
     $(this).fileupload('option', 'done') 
      .call(this, $.Event('done'), {result: result}); 
    }); 
}); 

</script> 

這個代碼是基於main.js,我只是改變了網址,並刪除塊github.io。網址在這裏很重要,因爲它用來刪除上傳的文件。

步驟3:服務器頁

$uploadDir = APP_FILE_PATH."/".$_REQUEST['folder']; 
    $upload_handler = new UploadHandler(array(
     "script_url" => "index.php?module=fileupload&mode=server&folder=".$_REQUEST['folder'], 
     "upload_dir" => $uploadDir, 
     "download_via_php" => 1, 
    )); 

模式參數僅用於不同iframe的頭版或在我的框架服務器請求的請求。

所以這是我的解決方案,它可以用我的框架爲我工作,也許有一個更簡單的解決方案,我不知道。

相關問題