input file獲得文件根目錄簡單實(shí)現(xiàn)
更新時間:2013年04月26日 15:45:14 作者:
js獲得file根目錄,然后賦值給hidden類型input,然后就可以交給php or jsp 處理了,感興趣的朋友可以參考下哈,希望可以幫助到你
其實(shí)問題很簡單
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>煙臺大學(xué)體測</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
復(fù)制代碼 代碼如下:
<!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>煙臺大學(xué)體測</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 處理了
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
PHP代碼加密和擴(kuò)展解密實(shí)戰(zhàn)
這篇文章主要介紹了PHP代碼加密和擴(kuò)展解密實(shí)戰(zhàn),對加密解密感興趣的同學(xué),可以參考下2021-04-04
thinkphp使用phpmailer發(fā)送郵件的方法
這篇文章主要介紹了thinkphp使用phpmailer發(fā)送郵件的方法,包含了配置發(fā)送郵件類、設(shè)置參數(shù)及發(fā)送郵件測試等的具體步驟,具有一定的實(shí)用價值,需要的朋友可以參考下2014-11-11
PHP基于pdo的數(shù)據(jù)庫操作類【可支持mysql、sqlserver及oracle】
這篇文章主要介紹了PHP基于pdo的數(shù)據(jù)庫操作類,可實(shí)現(xiàn)基本的數(shù)據(jù)庫連接、增刪改查、關(guān)閉連接等操作,還支持針對mysql、sqlserver及oracle等數(shù)據(jù)庫的操作,需要的朋友可以參考下2018-05-05
深入研究PHP中的preg_replace和代碼執(zhí)行
這篇文章主要給大家介紹了關(guān)于PHP中preg_replace和代碼執(zhí)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08
php實(shí)現(xiàn)轉(zhuǎn)換html格式為文本格式的方法
這篇文章主要介紹了php實(shí)現(xiàn)轉(zhuǎn)換html格式為文本格式的方法,通過一個自定義函數(shù)實(shí)現(xiàn)針對HTML標(biāo)簽的過濾,涉及php正則替換的相關(guān)操作技巧,需要的朋友可以參考下2016-05-05
php實(shí)現(xiàn)將HTML頁面轉(zhuǎn)換成word并且保存的方法
這篇文章主要介紹了php實(shí)現(xiàn)將HTML頁面轉(zhuǎn)換成word并且保存的方法,結(jié)合實(shí)例形式分析了PHPWord工具的功能與使用方法,具有一定參考借鑒價值,需要的朋友可以參考下2016-10-10

