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:''}")

ajaxFileUpload + lua-resty-upload 上传文件的更多相关文章

  1. Struts Upload上传文件

    1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...

  2. element-ui upload上传文件并携带参数 使用formData对象

    需求:上传文件的时候,需要携带其他的参数 问题:使用upload上传文件时,必须使用formData对象,而其他的参数通过data获取的到的,formData和data是不能同时传输的 解决:获取到的 ...

  3. thinkphp Upload上传文件在客户端生成的临时文件$_FILES['file']['tmp_name']

    1.关于thinkphp 的Upload的$_FILES['file']['tmp_name'] 在使用thinkphp上传图片的时候,在上传的$_FILES数组中,有一个$_FILES['file' ...

  4. Element-UI中Upload上传文件前端缓存处理

    Element-UI对于文件上传组件的功能点着重于文件传递到后台处理,所以要求action为必填属性.但是如果需要读取本地文件并在前端直接处理,文件就没有必要传递到后台,比如在本地打开一个JSON文件 ...

  5. [javascript] ajaxfileupload.js 跨域上传文件

    原文地址: http://www.ueffort.com/jqueryajaxfileupload-js-duo-wen-jian-shang-chuan-chuan-zhi-kua-yu/ 跨域 这 ...

  6. 异步上传文件,ajax上传文件,jQuery插件之ajaxFileUpload

    http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 一.ajaxFileUpload是一个异步上传文件的jQuery插件. ...

  7. jquery 实现ajax 上传文件的功能(使用插件 ajaxfileupload)

    js文件的下载地址 : http://files.cnblogs.com/wangqc/ajaxfileupload.js 页面代码: <html>    <!-- 引入相关的js文 ...

  8. ajaxfileupload原理及用法,主要用于即想用ajax序列化传递参数,又必须上传文件

    一,原理 AjaxFileUpload.js并不是一个很出名的插件,只是别人写好的放出来供大家用,原理都是创建隐藏的表单和iframe然后用JS去提交,获得返回值. 当初做了个异步上传的功能,选择它因 ...

  9. jquery ajaxFileUpload异步上传文件

    ajaxFileUpload.js 很多同名的,因为做出来一个很容易. 我用的是这个:https://github.com/carlcarl/AjaxFileUpload 下载地址在这里:http:/ ...

  10. jquery.uploadify上传文件配置详解(asp.net mvc)

    页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...

随机推荐

  1. jq 轮播图

    <style> #focus{width:500px;height:200px;overflow:hidden;/*用一个div把图片包含设置超出范围隐藏*/} </style> ...

  2. jquery文件上传控件 Uploadify 问题记录

    Uploadify v3.2.1 首先引用下面的文件 <!--上传控件 uploadify--> <script type="text/javascript" s ...

  3. Android之Picasso --zz

    简介: Picasso是Square公司开源的一个Android图形缓存库.可以实现图片下载和缓存功能. 特点: 1.加载载网络或本地图片并自动缓存处理: 2.链式调用: 3.图形转换操作,如变换大小 ...

  4. Application.ProcessMessages用法

    参考:http://cqujsjcyj.iteye.com/blog/380926 我想你可能还有点模糊.举个例子容易明白:假如你的窗体上有两个按钮,一个“计算”,一个“停止”, 如果你的计算是密集运 ...

  5. 【转载】PHP使用1个crontab管理多个crontab任务

    转载来自: http://www.cnblogs.com/showker/archive/2013/09/01/3294279.html http://www.binarytides.com/php- ...

  6. Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片

    设置 背景颜色和背景图片 首先设置autoFillBackground属性为真然后定义一个QPalette对象设置QPalette对象的背景属性(颜色或图片)最后设置QWidget对象的Palette ...

  7. NBU官方Doc網址https://www.veritas.com/support/en_US/article.DOC5332

    NBU(NetBackup) 7.0之後的版本官方文檔鏈接地址: https://www.veritas.com/support/en_US/article.DOC5332

  8. 限制非安全IP访问

    这个是一个检测ip是否非法的php函数,适应于白名单,黑名单功能开发,主要场景应用于:api来源限制,访问限制等. /** * 安全IP检测,支持IP段检测 * @param string $ip 要 ...

  9. [Oracle] PL/SQL学习笔记

    -- 1. 使用一个变量 declare -- Local variables here v_name ); begin -- Test statements here select t.user_n ...

  10. Unity3d 提示 "The scripts file name does not match the name of the class defined in the script!"的解决办法

    有两个原因,一个是文件的名称和类名不一致 第二个原因是有命名空间, 排除应该是可以修复的