input file获得文件根目录简单实现
内容摘要
其实问题很简单 index.html 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional
文章正文
其实问题很简单
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>
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>
代码注释