首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向Uploadifive/Uploadify添加输入字段

向Uploadifive/Uploadify添加输入字段
EN

Stack Overflow用户
提问于 2013-09-27 11:26:28
回答 5查看 2.4K关注 0票数 1

我一直在寻找如何添加输入字段并将额外的变量传递给uploadifive.php文件的答案。然而,我不能让任何张贴的解决方案工作,大多数时候,我找到的那些解决方案从来没有列出为有效或已解决。

谁能告诉我怎样才能将输入字段的内容传递给uploadifive.php文件?

这是我的HTML

代码语言:javascript
复制
<input type="text" name="student" id="student" placeholder="Your Student ID" value="" />
<input id="file_upload" name="file_upload" type="file" multiple="true">
<a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>

这是javascript

代码语言:javascript
复制
<?php $timestamp = time();?>
    $(function() {
        $('#file_upload').uploadifive({
            'auto'     : false,
            'method'   : 'post',
            'formData' : {
                'timestamp' : '<?php echo $timestamp;?>',
                'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                'student'   : $('#student').val()
                      },
                'queueID'          : 'queue',
                'uploadScript'     : 'uploadifive.php',
                'onUploadComplete' : function(file, data) { console.log(data); }
            });
        });

下面是我试图在php文件中使用它的方法,但没有传递任何值

代码语言:javascript
复制
$_POST['student']

如果有人能告诉我我做错了什么,我将不胜感激。

谢谢,加里

EN

回答 5

Stack Overflow用户

发布于 2014-05-15 14:59:48

我们需要读取的输入仍然存在

代码语言:javascript
复制
<input type="text" name="student" id="student" placeholder="Your Student ID" value="" />

使用这个js作为指南(我只包含了示例中重要的选项):

代码语言:javascript
复制
$('#my_file').uploadifive ({
    'formData': {
        //Some data we already know
        'timestamp' : "1400137111",
        'token'     : "a9b7ba70783b617e9998dc4dd82eb3c5"
     },

     //This will be executed before the upload process starts, so here's where
     //you will get the values in your form and will add them to formData.
     'onUpload': function(filesToUpload) {
         //Most of jQuery plugins, and luckily this one, uses the function jQuery.data
         //to save the settings we use on plugin's initialization.
         //In this case we can find those settings like this:
         var settings = $(this).data('uploadifive').settings;

         //Now we need to edit formData and add our input's value
         settings.formData.student = $('#student').val();

         //formData has the value readed from the input, so we store 
         //it again using jQuery.data
         $(this).data('uploadifive').settings = settings;

         //After this the plugin will perform the upload, reading the settings with
         //jQuery.data and our input's value will be present
     },

});
票数 2
EN

Stack Overflow用户

发布于 2013-09-27 16:13:33

您的代码无法正常工作,因为在页面加载时,会将#student input字段的值传递给uploadify formData。此时,字段的值为空,因此在PHP脚本中得到的值为空值。

您需要做的是在上载开始时准确地读取字段的值。要做到这一点,你必须实现uploadify对象的onUploadStart方法。

有关详细信息,请查看the documentation。您还会发现一个动态设置formData的示例。

票数 1
EN

Stack Overflow用户

发布于 2013-09-27 16:07:47

代码语言:javascript
复制
$('#file_upload') is undefined at the moment when you call the function 

您应该考虑使用document.ready,以便加载所有dom元素,并且可以使用jquery引用这些元素。

代码语言:javascript
复制
javascript:$('#file_upload').uploadifive('upload') of code is also unnecessary 

请阅读文档并查看他们的演示中的演示他们已经定义了uploadifive

1: dom的最后一个http://www.uploadify.com/demos/这就是为什么他们没有使用document.ready

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19042207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档