zoukankan      html  css  js  c++  java
  • 在OpenWrt中上传文件至路由器

    上传功能的整体逻辑比较简单,主要是对luci.http.setfilehandler方法的使用。对于这个方法,有一个比较特殊的地方即这个方法一定要放在最前面(除声明语句)。

     1 <%
    2 local h = require "luci.http"
    3 local io = require "nixio"
    4 local flag = true
    5 local run = true
    6 local fd = nil
    7
    8 -- 在这之前是不能有任何语句,声明语句除外
    9 h.setfilehandler(
    10 function(field, chunk, eof)
    11 if not field or not run then return end
    12
    13 if flag then
    14 h.write("上传中")
    15 flag = false
    16 end
    17
    18 -- 将上传的文件保存到根目录下
    19 local path = "/" .. field.file
    20
    21 if not fd then
    22 fd = io.open(path, "w")
    23 end
    24
    25 fd:write(chunk)
    26
    27 if eof and fd then
    28 fd:close()
    29 fd = nil
    30
    31 h.write("<br />上传完成")
    32 end
    33 end
    34 )
    35
    36 -- 这块代码一定也要放在setfilehandler下面。
    37 if h.formvalue("act") == "update" then
    38 return
    39 end
    40 %>
    41 <form id="update" name="update" action="<%=REQUEST_URI%>" method="post" enctype="multipart/form-data">
    42 <input type="hidden" name="act" value="update" />
    43 选择需要上传的文件:
    44 <input type="file" id="updatePackage" name="updatePackage" />
    45 <input type="submit" id="updateBtn" class="cbi-button cbi-button-apply" value="升级" />
    46 </form>


     

  • 相关阅读:
    7. ZooKeeper的stat结构
    6. ZooKeeper访问控制列表
    5. 监视和ZooKeeper操作
    4. ZooKeeper 基本操作
    3.Apache ZooKeeper数据模型
    Eclipse安装Activiti Designer插件
    Javascript Canvas验证码
    Tomcat9配置SSL连接
    JAVA将异常的堆栈信息转成String
    SpringBoot2静态资料访问
  • 原文地址:https://www.cnblogs.com/AUOONG/p/2433066.html
Copyright © 2011-2022 走看看