Php 通过Uploadify发送附加字段数据
我想用uploadify发送一些额外的(表单)字段数据。为此,我使用scriptData。例如,下面的代码正确地发送name和location字段的静态值Php 通过Uploadify发送附加字段数据,php,jquery,Php,Jquery,我想用uploadify发送一些额外的(表单)字段数据。为此,我使用scriptData。例如,下面的代码正确地发送name和location字段的静态值 <script type="text/javascript"> $(document).ready(function() { $("#fileUpload").fileUpload({ 'uploader': 'uploadify/uploader.swf', 'cancelImg': 'u
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload").fileUpload({
'uploader': 'uploadify/uploader.swf',
'cancelImg': 'uploadify/cancel.png',
'script': 'uploadify/upload.php',
'folder': 'files',
'multi': false,
'displayData': 'speed',
'scriptData': {'name':'JohnDoe', 'location':'Australia'}
});
});
</script>
在upload.php上,我正在尝试
$name = $_GET['name'];
$location = $_GET['location'];
但它没有得到任何值。关于这一点,请帮助我,我如何发送其他字段数据。谢谢。您需要指定发布变量的方法: 在上载配置中:
//...
'method': 'POST',
//...
因为在加载DOM时调用val()
,而不是在用户键入位置和名称时调用。您应该使用其中一个事件来设置新值。手册不清楚,我想它一定是onSelectOnce
事件:
<script type="text/javascript">
$(document).ready(function() {
$("#fileUpload").fileUpload({
'uploader': 'uploadify/uploader.swf',
'cancelImg': 'uploadify/cancel.png',
'script': 'uploadify/upload.php',
'folder': 'files',
'multi': false,
'displayData': 'speed',
'scriptData': {'name':'', 'location':''},
'onSelectOnce' : function(event,data) {
$("#fileUpload").uploadifySettings('scriptData', {'name' : $('#name').val(), 'location' : $('#location').val()});
}
});
});
</script>
$(文档).ready(函数(){
$(“#fileUpload”).fileUpload({
'uploader':'uploadify/uploader.swf',
'cancelImg':'uploadify/cancel.png',
'script':'uploadify/upload.php',
'文件夹':'文件',
“多重”:错误,
“显示数据”:“速度”,
'scriptData':{'name':'','location':''},
“onSelectOnce”:函数(事件、数据){
$(“#fileUpload”).uploadifySettings('scriptData',{'name':$('#name').val(),'location':$('#location').val());
}
});
});
您是否尝试在希望进行JSON编码的值周围加引号?i、 e.将$('.\location').val()
替换为“\'”+$('.\location').val()+“\'”
这里是uploadify 3.1的代码
$(function() {
$('#file_upload').uploadify({
'formData' : {'id' : ''},
'debug': false,
'buttonClass' : 'g-button g-button-blue',
'swf' : '../uploadify/uploadify.swf',
'uploader' : 'ajax/my_upload_file.php',
'onUploadStart' : function(file) {
$('#file_upload').uploadify('settings', 'formData', {'id' : $('#id').val() });
}
});
});
我需要使用它,因为我用json调用我的表单数据,然后我必须更新uploadify id post参数我认为post是默认方法,但即使添加了它也没关系。这很奇怪,你使用的uploadify的版本是什么?
$(function() {
$('#file_upload').uploadify({
'formData' : {'id' : ''},
'debug': false,
'buttonClass' : 'g-button g-button-blue',
'swf' : '../uploadify/uploadify.swf',
'uploader' : 'ajax/my_upload_file.php',
'onUploadStart' : function(file) {
$('#file_upload').uploadify('settings', 'formData', {'id' : $('#id').val() });
}
});
});