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短域名转换为实际域名函数

复制代码 代码如下: $url = "http://sinaurl.cn/hbdsU5"; echo unshorten($url); function unshorten($url)...

php基于ob_start(ob_gzhandler)实现网页压缩功能的方法

php基于ob_start(ob_gzhandler)实现网页压缩功能的方法

本文实例讲述了php基于ob_start('ob_gzhandler')实现网页压缩功能的方法。分享给大家供大家参考,具体如下: PHP生成网页后传送给浏览器显示 ,页面的打开速度除了与...

PHP使用file_get_contents发送http请求功能简单示例

本文实例讲述了PHP使用file_get_contents发送http请求功能。分享给大家供大家参考,具体如下: 服务器端模拟 POST/GET 等请求,使用 CURL 很容易办到(例如...

解析PHP中数组元素升序、降序以及重新排序的函数

1,快速创建数组的函数range()比如range()函数可以快速创建从1到9的数字数组:复制代码 代码如下:<?php $numbers=range(1,9);echo $num...

php格式输出文件var_export函数实例

本文实例讲述了php格式输出文件var_export函数的用法。分享给大家供大家参考。具体如下: var_export:php 4 >= 4.2.0, php 5 var_expo...