当前位置: 代码迷 >> Web前端 >> 读取资料的路径和文件夹的目录
  详细解决方案

读取资料的路径和文件夹的目录

热度:81   发布时间:2012-10-27 10:42:26.0
读取文件的路径和文件夹的目录
本地上传时读取本地文件的路径<form   name= "form1 "   enctype= "multipart/form-data "   method= "post" action= "">
    <input   type= "file" name="file">
    <input   type= "submit"   name= "Submit "   value= "上传 ">
</form>


下载到本地时设置本地文件夹的目录路径
首先在JS里添加函数
<script language="JavaScript" type="text/JavaScript">
function browseFolder(path)  {
      try  {
         var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939";  //选择框提示信息
         var Shell = new ActiveXObject("Shell.Application");
         var Folder = Shell.BrowseForFolder(0, Message, 64, 17);//起始目录为:我的电脑
   //var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为:桌面
          if (Folder != null)  {
              Folder = Folder.items();  // 返回 FolderItems 对象
              Folder = Folder.item();  // 返回 Folderitem 对象
              Folder = Folder.Path;   // 返回路径
              if (Folder.charAt(Folder.length - 1) != "\\")  {
                  Folder = Folder + "\\";
              }
              document.getElementById(path).value = Folder;
             return Folder;
          }
      }
      catch (e)  {
          alert(e.message);
      }
}

</script>

然后在JSP里

                           <td>
                             <input type="text" name="path" />
                         </td>
                         <td>
                             <input type="button" onclick="browseFolder('path')"
                                  value="选择生成路径" />
                         </td>


  相关解决方案