【openwrt】——iframe+lua页面不刷新上传文件
<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>
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