【openwrt】——iframe+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