读书人

【openwrt】iframe+lua页面不刷新

发布时间: 2013-03-29 14:24:52 作者: rapoo

【openwrt】——iframe+lua页面不刷新上传文件

1.html代码
<form name="upfile" target="iframeUpload" action="upload.lua" method="post" enctype="multipart/form-data" >
<iframe name="iframeUpload" src="" frameborder="0" SCROLLING="no" style="display:NONE"></iframe>
<input type="hidden" name="act" value="upload" />
<input type='file' name="upload" id='dest_ppd_file'/>
<input type="submit" id="uploadfile" name="submit" value="Upload" />
<script>
function uploadOver()
{
alert("upload over!");
}
</script>
</form>


2.lua代码——upload.lua

local h = require "luci.http"
local io = require "nixio"
local flag = true
local run = true
local fd

h.setfilehandler(
function(filed, chunk, eof)
if not filed or not run then
return
end

if flag then
flag = false
end

filename = filed.file
dest_filename = filed.file
fn_flag = string.find(filename, "\\")
if fn_flag then
dest_filename = string.match(filename, ".+\\([^\\]*%.%w+)$")
end

fn_flag = string.find(filename, "/")
if fn_flag then
dest_filename = string.match(filename, ".+/([^/]*%.%w+)$")
end

local path = "/tmp/" .. dest_filename

if not fd then
fd = io.open(path, "w")
end

fd:write(chunk)

if eof and fd then
fd:close()
fd = nil
end
h.write("<script>parent.uploadOver()</script>")
end)

if h.formvalue("act") == "upload" then
return
end



参考资料:

http://www.oschina.net/code/snippet_54371_4502

http://www.cnblogs.com/AUOONG/archive/2012/04/05/2433066.html




读书人网 >编程

热点推荐