其實問題很簡單
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>