ajaxFileUpload下载地址

地址:http://pan.baidu.com/s/1mgJypz6

html页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Untitled</title>
<script src="jquery-1.7.1.js"></script>
<script src="ajaxfileupload.js"></script>
<script type="text/javascript">
$(function () {
$(":button").click(function () {
ajaxFileUpload();
})
})
function ajaxFileUpload() {
$.ajaxFileUpload
(
{
url: '/dsideal_yy/rating/test', //用于文件上传的服务器端请求地址
fileElementId: 'file1', //文件上传空间的id属性 <input type="file" id="file" name="file" />
dataType: 'json', //返回值类型 一般设置为json
success: function (data) //服务器成功响应处理函数
{
alert(data.msg);
}
}
)
return false;
}
</script>
</head>
<body>
<body>
<p><input type="file" id="file1" name="file" /></p>
<input type="button" value="上传" />
</body>
</html>

lua代码

local upload = require "resty.upload"
local uuid = require "resty.uuid"; local chunk_size =
local form = upload:new(chunk_size)
local file --获取文件名
function get_filename(res)
local filename = ngx.re.match(res,'(.+)filename="(.+)"(.*)')
if filename then
return filename[]
end
end --获取文件扩展名
function getExtension(str)
return str:match(".+%.(%w+)$")
end while true do
local typ, res, err = form:read()
if not typ then
ngx.say("{error:'error', msg:'"..tostring(err).."',imgurl:''}")
return
end
if typ == "header" then
if res[] ~= "Content-Type" then
local file_id = uuid.new()
local filen_ame = get_filename(res[])
local extension = getExtension(filen_ame)
local dir = string.sub(file_id,,)
local file_name = "/usr/local/tomcat7/webapps/dsideal_yy/html/down/Material/"..dir.."/"..file_id.."."..extension
if file_name then
file = io.open(file_name, "w+")
if not file then
ngx.say("{error:'error', msg:'failed to open file',imgurl:''}")
return
end
end
end
elseif typ == "body" then
if file then
file:write(res)
end
elseif typ == "part_end" then
file:close()
file = nil
elseif typ == "eof" then
break
else
-- do nothing
end
end ngx.say("{error:'success', msg:'上传成功!',imgurl:''}")

最新文章

  1. 绝对炫的3D幻灯片-SLICEBOX
  2. JavaScript中的splice方法
  3. python——threading模块
  4. urllib+BeautifulSoup无登录模式爬取豆瓣电影Top250
  5. Non-Programmer&#39;s Tutorial for Python 3/File IO
  6. php部分--数组(包含指针思想遍历数组);
  7. VS中设置#define _CRT_SECURE_NO_WARNINGS的两种方式
  8. svg学习笔记(二)
  9. Java中的构造方法
  10. Redhat Linux 自动修改密码
  11. Centos下MariaDB操作
  12. C# 使用运算符重载 简化结果判断
  13. Ubuntu16.04首次root登录设置
  14. 修改mongodb(带仲裁节点的副本集)各机器端口
  15. Archiva 2.2.3 安装运行的时候出现协议版本错误
  16. hbase源码系列(十五)终结篇&amp;Scan续集--&gt;如何查询出来下一个KeyValue
  17. Gradle 设置全局代理
  18. centos6安装自带php
  19. org.apache.commons.lang.StringUtils的常用方法
  20. QQ空间点赞代码

热门文章

  1. MVC基础知识 – 1.抽象工厂模式
  2. Python 小游戏 Bunny
  3. Eclipse中怎么设置Add cast to Clazz 快捷键
  4. 【PHP构造方法和析构方法的使用】
  5. 获取Windows下某进程监听的TCP/UDP端口
  6. struts拦截器实现原理
  7. Java Hour 65 [译] Java 6.0 说明
  8. [Linux] 解压tar.gz文件,解压部分文件
  9. C++ list的基本操作和使用
  10. POJ 1655 Balancing Act 树的重心