在 uploadify/uploadifive 上动态设置 formData
🕛 by pyList at 2014-11-17 23:11
uploadify/uploadifive 是很棒的上传插件,有时候需要动态设置表单数据,下面就对动态设置表单做一下使用记录。
在 onAddQueueItem 事件里添加
如果是自动上传的,可在 onAddQueueItem
事件里添加一个函数设置 settings.formData
,参考如下
(去掉formData,用下面的代替)
'onAddQueueItem' : function(file) {
this.data('uploadifive').settings.formData = { 'someKey' : $('#formFieldID').val() };
}
手动上传
若要手动上传的,可在调用upload 前改变要引用的值,参考以下代码:
function uploadFiles() {
$('#file_upload').data('uploadifive').settings.formData = { 'someKey' : $('#formFieldID').val() };
$('#file_upload').uploadifive('upload', '*');
}
单独设置
'onUpload' : function(){
$('#file_upload').data('uploadifive').settings.formData = { 'additional_form_data' : $('#additional_form_data').val() }
},
手把手一步一步设置
<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
},
});
妙
$("#file_upload").uploadify('settings','formData' ,{'currentDirPath': /webroot/newsletter/update});
总结
- 用hidden input 保存key 和 token , 每次只能上传一个文件,
- 上传成功后重新请求key 和 token,
- 把返回的key 和 token 保存在hidden input 里。
获取文件名
上传之前,选中文件后获取文件名
$(function() {
$('#file_upload').uploadifive({
'uploadScript' : '/uploadifive.php'
'onUploadFile' : function(file) {
alert('The file ' + file.name + ' is being uploaded.');
}
});
});
$("#file_upload").uploadify({
'swf' : '/uploadify/uploadify.swf',
'uploader' : '/uploadify/uploadify.php',
'onSelect' : function(file) {
alert('The file ' + file.name + ' was added to the queue.');
}
});
$("#file_upload").uploadify({
'swf' : '/uploadify/uploadify.swf',
'uploader' : '/uploadify/uploadify.php',
'onUploadStart' : function(file) {
$("#file_upload").uploadify("settings", 'formData', {'title' : $("#title").val()});
}
});
});
本文网址: https://pylist.com/t/1416237067 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
发表第一条评论!
相关推荐
小工具
标签
cpulimit
cpu
使用率
动态
进程
linux
ulimit
永久
设置
系统
默认值
struct
pip
镜像
常用
国内
xor
python
解密
加密
方法
u盘
mac
diskutil
格式化
顽固
之坑
files
golang
open
服务
app
store
登录
未知
xmltodict
gbk
xml
编码
openwrt
usb
上网卡
共享
网络
bbr
路由
开启
sqlite
数据库
提速
经验
固件
debian
ubuntu
编译
系统启动
硬件加速
ubnt
er
最新版
wndr4300
升级
访问速度
vps
加速
js
fonts
css
html
一键
字符串
中文
分割
英文
后缀名
并取
遍历
文件夹
failed
load
devtools
sourcemap
chrome
自动更新
microsoft
关闭
静音
风扇
主机
笔记本
改造
低功耗
web
爬虫
服务器
组装
微信
尝鲜
视频
体验
查看
温度
server
浏览
google
身份验证
authenticator
迁移
手机
webdriver
微博
selenium
gnu
安装
宅家
坑记
屏幕
动手
nginx
quic
抢先
最近发表
- Chrome 控制台 DevTools failed to load SourceMap 警告的消除方法
- Mac 关闭 Microsoft 自动更新
- Mac 登录 App Store 出现“发生了未知错误”的解决方法
- 老笔记本改造为无风扇静音主机方案
- 自己组装21瓦低功耗家庭爬虫、文件、web服务器
- 微信视频号尝鲜体验
- Ubuntu/Debian 查看CPU温度的方法
- 在Ubuntu/debian Server 系统使用Chrome 无头浏览模式
- 换手机后 Google 身份验证器 Google Authenticator 数据迁移的简单方法
- 使用Golang selenium WebDriver 自动登录微博
- 在 Ubuntu 或其它 GNU/Linux 系统下安装 Debian
- Mac 下制作 USB ubuntu/debian 系统启动、安装盘的几种方法
- ubuntu/debian 下自行编译 OpenWRT 固件
- 宅家自己动手换手机屏幕掉坑记
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- 在 Nginx 和 Golang web 上抢先体验 QUIC
最近浏览
- 用python 实现XOR 加密解密的方法
- 在终端使用Mac diskutil 命令格式化顽固U盘
- Golang 服务之坑:too many open files
- Mac 登录 App Store 出现“发生了未知错误”的解决方法
- python xmltodict 解析xml gbk 编码问题解决
- Openwrt 使用USB 4G 上网卡共享网络
- Openwrt 路由上开启BBR
- python SQLite 数据库提速经验
- ubuntu/debian 下自行编译 OpenWRT 固件
- Mac 下制作 USB ubuntu/debian 系统启动、安装盘的几种方法
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- WNDR4300 固件升级到 OpenWrt 最新版
- 开启BBR 加速小VPS访问速度
- 一键下载网站资源(html/css/js/fonts)
- python 分割中文英文混合字符串的正确方法
- 编写python脚本遍历文件夹并取指定后缀名文件