1

这是我的代码:

<script type="text/javascript">    
 $(function(){
   var btnUpload=$('#browse');
   var adinfoid=$('#adinfoid').val();

   new AjaxUpload(btnUpload, {
     action: '<?php echo base_url()?>index.php/post/upload_editmainimage/'+adinfoid,
     name: 'uploadfile',
     onSubmit: function(file, ext){
       if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
         $("#mainphotoerror").html('Only JPG, PNG, GIF, files are allowed');
         $("#mainphotoerror").css('display','block');
         return false;
       }        
     },
     onComplete: function(file, response){
       //alert(response);
       if(response){
         alert('success');
       }else{
         alert("error");
       }
     }
   });  
 });    
</script>

HTML 部分

<table width="200" border="1">
  <?php 
   for($i=0;$i<20;i++){
  ?>
  <tr>
    <td>Add Photo <?php echo $i;?></td>
    <td>
      <input type="button" 
             id="browse<?php echo $i;?>" 
             class="browse_media" 
             value="Browse">
    </td>
  </tr>
  <?php
   }
  ?>
</table>

当我点击第一个浏览按钮时,会显示文件打开窗口,但是从第二个到最后,没有显示用于选择图像的打开窗口。

我的代码中的问题在哪里?

我已经为 ajax 上传加载了 .js 文件?

如何使用 ajax 从多个文件浏览器按钮上传图像?

4

5 回答 5

0

You can try using this plugin http://blueimp.github.com/jQuery-File-Upload/

This is the best I have found so far. You can add as many files as you want with one add files button, it has both global and local progress bar and many other options.

于 2012-05-17T12:00:55.580 回答
0

您应该了解 HTML 上的 id 标签,它必须是唯一的 IDentifier

尝试这个:

var btnUploads=$('input.browse_media');
var adinfoid=$('#adinfoid').val();
new AjaxUpload(btnUploads, {

并在 php

<td><input type="button" id="browse<?php echo $i?>" class="browse_media" value="Browse"></td>
于 2012-05-17T06:34:42.740 回答
0

对于多个文件上传,请使用 Jquery 插件 uploadify() 检查演示链接:http ://www.uploadify.com/demos/

于 2012-05-17T06:36:11.567 回答
0
as Sergey mentioned id should be unique with in a html page and with in the ready function of jquery try this code of uploadify :

$(function() {
<?php for($i=0;$i<20;i++){?>

   $("#browse<?php echo $i?>").uploadify({
        height        : 30,
        swf           : '/uploadify/uploadify.swf',
        uploader      : '/uploadify/uploadify.php',
        width         : 120
    });
<?php }?>
});

更多检查uploadify网站

于 2012-05-17T06:48:27.373 回答
0

对于多个上传设置参数'multi':ture

    $(function() {
      $("#file_upload").uploadify({
        'multi'    : true,
        'swf'      : '/uploadify/uploadify.swf',
        'uploader' : '/uploadify/uploadify.php'
      });
   });
于 2014-06-03T08:36:20.403 回答