我一直在寻找如何添加输入字段并将额外的变量传递给uploadifive.php文件的答案。然而,我不能让任何张贴的解决方案工作,大多数时候,我找到的那些解决方案从来没有列出为有效或已解决。
谁能告诉我怎样才能将输入字段的内容传递给uploadifive.php文件?
这是我的HTML
<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
<?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文件中使用它的方法,但没有传递任何值
$_POST['student']如果有人能告诉我我做错了什么,我将不胜感激。
谢谢,加里
发布于 2014-05-15 14:59:48
我们需要读取的输入仍然存在
<input type="text" name="student" id="student" placeholder="Your Student ID" value="" />使用这个js作为指南(我只包含了示例中重要的选项):
$('#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
},
});发布于 2013-09-27 16:13:33
您的代码无法正常工作,因为在页面加载时,会将#student input字段的值传递给uploadify formData。此时,字段的值为空,因此在PHP脚本中得到的值为空值。
您需要做的是在上载开始时准确地读取字段的值。要做到这一点,你必须实现uploadify对象的onUploadStart方法。
有关详细信息,请查看the documentation。您还会发现一个动态设置formData的示例。
发布于 2013-09-27 16:07:47
$('#file_upload') is undefined at the moment when you call the function 您应该考虑使用document.ready,以便加载所有dom元素,并且可以使用jquery引用这些元素。
javascript:$('#file_upload').uploadifive('upload') of code is also unnecessary 请阅读文档并查看他们的演示中的演示他们已经定义了uploadifive
1: dom的最后一个http://www.uploadify.com/demos/这就是为什么他们没有使用document.ready
https://stackoverflow.com/questions/19042207
复制相似问题