input file获得文件根目录简单实现

yipeiwu_com6年前PHP代码库
其实问题很简单
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>

相关文章

PHP 常用函数库和一些实用小技巧

文件读取函式 //文件读取函式 function PHP_Read($file_name) { $fd=fopen($file_name,r); while($bufline=fgets...

PHP 的ArrayAccess接口 像数组一样来访问你的PHP对象

复制代码 代码如下: interface ArrayAccess boolean offsetExists($index) mixed offsetGet($index) void of...

做了CDN获取用户真实IP的函数代码(PHP与Asp设置方式)

asp函数代码:复制代码 代码如下:function checkip(checkstring)'用正则判断IP是否合法dim re1set re1=new RegExpre1.patte...

PHP中一个有趣的preg_replace函数详解

PHP中一个有趣的preg_replace函数详解

0x01 起因 事情的起因是下午遇到了 preg_replace 函数,我们都知道 preg_replace 函数可能会导致命令执行。现在我们来一些情况。 0x02 经过 踩坑1:...

关于Iframe如何跨域访问Cookie和Session的解决方法

最近做登录系统的整合,其中遇到的一个最关键的问题为在一个统一的后台里需要无障碍的访问另外一个系统后台,这个系统是第三方提供的一个加过密的系统,后台自动登录接口是自己分析出来的,没有单独提...