input file 获得文件根目录

来源:互联网 发布:积分软件 编辑:程序博客网 时间:2024/05/22 16:06

其实问题很简单
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>烟台大学体测</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">   function show_root(){     //var root = myform.file.value;      var root = document.getElementById("file").value; //alert(root); //document.getElementById("root").innerHTML=root; myform.root.value=root;   }</script></head><body>  <form name="myform" method="post" action="upload.php">      <input id="file" type="file" name="file"/>     <input id="root" type="hidden" name="root"/>     <input type="submit" name="submit" onclick="show_root()"/>   </form> </body></html>
upload.php

<?php echo $_POST["root"];

下面这段js代码就是获得file根目录,然后赋值给hidden类型input,然后就可以交给php or jsp 处理了

<script type="text/javascript">   function show_root(){     //var root = myform.file.value;      var root = document.getElementById("file").value; //alert(root); //document.getElementById("root").innerHTML=root; myform.root.value=root;   }</script>




原创粉丝点击