Php 向Uploadify/Uploadify添加输入字段
我一直在搜索如何添加输入字段并将额外的变量传递到uploadifive.php文件的答案。然而,我无法得到任何张贴的解决方案工作,大多数时候,我找到的解决方案从来没有列为工作或解决 有人能告诉我如何将输入字段的内容传递到uploadifive.php文件吗 这是我的HTMLPhp 向Uploadify/Uploadify添加输入字段,php,jquery,uploadify,Php,Jquery,Uploadify,我一直在搜索如何添加输入字段并将额外的变量传递到uploadifive.php文件的答案。然而,我无法得到任何张贴的解决方案工作,大多数时候,我找到的解决方案从来没有列为工作或解决 有人能告诉我如何将输入字段的内容传递到uploadifive.php文件吗 这是我的HTML <input type="text" name="student" id="student" placeholder="Your Student ID" value="" /> <input id="fil
<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>
如果有人能告诉我我做错了什么,我们该如何让它发挥作用,我会非常感激
谢谢,
加里
您应该考虑使用<代码>文档.Read ,以便加载所有DOM元素,并可以使用jQuery
引用javascript:$('#file_upload').uploadifive('upload') of code is also unnecessary
请阅读文档并在他们的[demo][1]中查看演示。他们已经定义了uploadifive
[1] :在dom的最后,这就是他们没有使用
文档的原因。ready
您的代码工作不正常,因为#student输入字段的值在页面加载时被传递以上载formData。此时,字段的值为空,因此PHP脚本中的值为空
您需要做的是在上传开始时读取字段的值。为此,必须实现uploadify对象的onUploadStart方法
查看详细信息。您还会发现一个动态设置formData的示例
<?php $timestamp = time();?>
function uploadFiles() {
$('#file_upload').data('uploadifive').settings.formData = {
'title' : $('#student').val(),
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
};
$('#file_upload').uploadifive('upload');
}
函数uploadFiles(){
$('#file_upload').data('uploadifive').settings.formData={
‘title’:$(‘学生’).val(),
“时间戳”:“,
“令牌”:”
};
$(“#文件上传”).uploadifive('upload');
}
忘记尝试向初始化添加任何内容,例如onUpload。不起作用。如果你去Uploadifive论坛,你会发现作者给出了几个不一致的答案,这些答案似乎包含语法错误,也不起作用
从初始化中完全删除formData,并将其移动到使用上载链接调用的单独函数。
您将在中找到详细的解释,我们需要阅读的输入仍然存在
<input type="text" name="student" id="student" placeholder="Your Student ID" value="" />
$(document).ready()已作为$()包含在代码中。这些代码是相等的()请检查我的答案。如果有用,将答案设置为已接受或投票。否则,只需写下答案中缺少的内容或您正在处理的问题,我将尽力提供帮助。您是正确的,但您提到的事件和您链接到的文档是供上传的。不幸的是,Uploadify的API与Uploadify相比有很大的不同。我还没有机会测试它,但是@sepelin的答案看起来是正确的。
javascript:$('#file_upload').uploadifive('upload') of code is also unnecessary
<?php $timestamp = time();?>
function uploadFiles() {
$('#file_upload').data('uploadifive').settings.formData = {
'title' : $('#student').val(),
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
};
$('#file_upload').uploadifive('upload');
}
<input type="text" name="student" id="student" placeholder="Your Student ID" value="" />
$('#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
},
});