2013-12-22 48 views
0

我正在使用Blueimp Jquery文件上傳插件(http://blueimp.github.io/jQuery-File-Upload/)。我無法轉移現有會話。所以我想,第二個TextForm是個好主意。但我認爲,劇本不是通過標準格式提交的。腳本通過jQuery/json提交。但是POST數據不會出現。jQuery文件上傳:傳輸POST-或會話數據

這裏讀了的getJSON-功能需要擴展:Jquery File Upload plugin: Dynamically change upload path?

但我不能找到這個功能。有人知道這個功能嗎?

這裏是Upload-Form,它將數據發送到PHP-UploadHandler。

<?php 
ob_start(); 
?> 
<!DOCTYPE HTML> 

<html lang="en"> 
<head> 
<!-- Force latest IE rendering engine or ChromeFrame if installed --> 
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]--> 
<meta charset="utf-8"> 
<!-- Bootstrap styles --> 
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> 

<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars --> 
<link rel="stylesheet" href="/upload/css/jquery.fileupload.css"> 
</head> 
<body> 

<div class="container"> 

    <!-- The fileinput-button span is used to style the file input field as button --> 
    <span class="btn btn-success fileinput-button"> 
     <i class="glyphicon glyphicon-plus"></i> 
     <span>Select files...</span> 
     <!-- The file input field used as target for the file upload widget --> 
     <input id="fileupload" type="file" name="files[]" multiple> 
     <input type="hidden" name="sessionuse" value="<? echo $_SESSION['userid'];?>"> 
    </span> 
    <br> 
    <br> 
    <!-- The global progress bar --> 
    <div id="progress" class="progress"> 
     <div class="progress-bar progress-bar-success"></div> 
    </div> 
    <!-- The container for the uploaded files --> 
    <div id="files" class="files"></div> 
    <br> 
    <div class="panel panel-default"> 

    </div> 
</div> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included --> 
<script src="js/vendor/jquery.ui.widget.js"></script> 
<!-- The Iframe Transport is required for browsers without support for XHR file uploads --> 
<script src="js/jquery.iframe-transport.js"></script> 
<!-- The basic File Upload plugin --> 
<script src="js/jquery.fileupload.js"></script> 
<!-- Bootstrap JS is not required, but included for the responsive demo navigation --> 
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
<script> 
/*jslint unparam: true */ 
/*global window, $ */ 
$(function() { 
    'use strict'; 
    // Change this to the location of your server-side upload handler: 
    var url = window.location.hostname === 'blueimp.github.io' ? 
       '//jquery-file-upload.appspot.com/' : 'server/php/'; 
    $('#fileupload').fileupload({ 
     url: url, 
     dataType: 'json', 
     done: function (e, data) { 
      $.each(data.result.files, function (index, file) { 
       $('<p/>').text(file.name).appendTo('#files'); 
      }); 
     }, 
     progressall: function (e, data) { 
      var progress = parseInt(data.loaded/data.total * 100, 10); 
      $('#progress .progress-bar').css(
       'width', 
       progress + '%' 
      ); 
     } 
    }).prop('disabled', !$.support.fileInput) 
     .parent().addClass($.support.fileInput ? undefined : 'disabled'); 
}); 
</script> 
</body> 
</html> 
<?php 
ob_end_flush(); 
?> 

回答

0

你需要,如果你希望自己的內容會與您的插件會自動發送到你的嵌入到input標籤<form>。你可以在控制檯上看到this fiddle的區別。

還有第二種方式發送額外的數據與上傳的文件:formData option