dongqu2863 2012-03-05 02:12
浏览 145

AJAX文件上传传递ID

I am using this AJAX File Upload plugin:

http://www.phpletter.com/Demo/AjaxFileUpload-Demo/

I made this function that will loop through all file inputs

function ajaxFileUpload() {
        $('input[type=file]').each(function() {
            $.ajaxFileUpload ({
                url:'upload.inc.php',
                secureuri:false,
                fileElementId:this.id,
                dataType: 'json'
            })
        });
        return false;

The problem is, I am uploading files to two different folders. All file inputs have 'name="image"' on them. So I need to create a conditional statement to tell the program what folder I should put them in. But in order for me to do this, I need to get the class the file input so I can create something like this:

switch(fileInputClass) {
case 'mainImage':
//upload to folder 1
break;
case 'subImage':
//upload to folder 2
}

So how can I pass the class string to my 'upload.inc.php' so that I can conditionally tell what folder it should be uploaded to? Thanks!

  • 写回答

1条回答 默认 最新

  • dougou1127 2012-03-05 02:20
    关注

    You can pass it as a querystring parameter along with the url.

    Try something like this

     function ajaxFileUpload() {
        $('input[type=file]').each(function() {
            $.ajaxFileUpload ({
                url: getUploadUrl(this.className),
                secureuri:false,
                fileElementId:this.id,
                dataType: 'json'
            })
        });
        return false;
     }
    
     function getUploadUrl(class){
         switch(class) {
             case 'mainImage':
                  return 'upload.inc.php?uploadfolder=folder1'
             case 'subImage':
                  return 'upload.inc.php?uploadfolder=folder2'
          }
     }
    

    On the server side get the querystring value using $_GET['uploadfolder']

    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等