简体   繁体   English

AJAX文件上传传递ID

[英]AJAX File Upload passing ID

I am using this AJAX File Upload plugin: 我正在使用这个AJAX文件上传插件:

http://www.phpletter.com/Demo/AjaxFileUpload-Demo/ 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. 所有文件输入都有'name =“image”'。 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? 那么如何将类字符串传递给我的'upload.inc.php',以便我可以有条件地告诉它应该上传到哪个文件夹? Thanks! 谢谢!

You can pass it as a querystring parameter along with the url. 您可以将其作为查询字符串参数与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'] 在服务器端使用$_GET['uploadfolder']获取查询字符串值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM