gpt4 book ai didi

php - 向 Uploadive/Uploadify 添加输入字段

转载 作者:行者123 更新时间:2023-12-01 08:02:12 24 4
gpt4 key购买 nike

我一直在寻找如何添加输入字段并将额外变量传递到 uploadive.php 文件的答案。但是,我无法让任何已发布的解决方案发挥作用,而且大多数时候,我找到的这些解决方案从未被列为有效或已解决。

有人可以告诉我如何将输入字段的内容传递到 uploadive.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']

如果有人能告诉我我做错了什么以及如何让它发挥作用,我将非常感激。

谢谢,加里

最佳答案

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

<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
},

});

关于php - 向 Uploadive/Uploadify 添加输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19042207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com