3

私は、まさにこの質問に関していくつかの質問があったことを知っています.私はそれらの多くをくまなく調べましたが、目標を適切に達成するための正しい方法を見つけていません. 基本的に、フォーム内の複数のファイル入力をキャプチャして PHP にプッシュしようとしています。私は少なくともPHPの部分を理解していますが、そのJqueryは苦労しています。デバッグ中に気付いた主な問題の 1 つは、アクション パラメーターがまったく処理されないことです。私が投稿したコードは以下のとおりです。どんな助けでも大歓迎です。ありがとう。

$(document).ready(function () {
  //if submitting imgages form
  $('#submit').click(function () {
    // match anything not a [ or ]
    regexp = /^[^[\]]+/;
    var fileInput = $('.putImages input[type="file"]');
    var fileInputName = regexp.exec(fileInput.attr('name'));

    // make files available
    var data2 = new FormData(fileInput);
    jQuery.each($(fileInput)[0].files, function (i, file) {
      data2.append(fileInputName + '[' + i + ']', file);
    });

    //organize data
    var data = new FormData($('input[name^="uploadFile"]'));
    jQuery.each($('input[name^="uploadFile"]')[0].files, function (i, file) {
      data.append(i, file);
    });

    $.ajax({
      type: 'GET',
      url: 'productadminupdate.php',
      data: data2 + "&action=" + 'images',
      cache: false,
      contentType: false,
      processData: false,
      success: function (response) {
        $('#imgform_result').html(response).fadeIn();
      }
    });

    return false;
  });
});
4

1 に答える 1

1

理解できたかどうかはわかりませんが、人々は ajax アップローダについて考えるとき、実際にはそれを知りません。実際には、JavaScript がその役割を果たしているわけではありません。この手法は、フォームのアクションを Iframe にターゲティングする際に存在します。この Iframe は非表示にする必要があります。次に例を示します。

<form method='post' enctype='multipart/form-data' action='YOUR_FILE.php' target='upload_iframe'>        
    <label>photo1:</label>
    <input type='file' name='photo1'/>
    <label>photo2:</label>
    <input type='file' name='photo2'/>
    <label>photo3:</label>
    <input type='file' name='photo3'/>
    <label>photo4:</label>
    <input type='file' name='photo4'/>
    <label>photo5:</label>
    <input type='file' name='photo5'/>
    <input type='submit' value='Send'/>
    </form>
</div>
<iframe name='upload_iframe'></iframe>

したがって、iframe では、php コードがアップロードを行い、$_FILES を使用して情報を取得します。

于 2012-09-02T03:05:21.690 に答える