php HTML file 获取绝对路径

在php编程中,上传文件的时,往往我们有时候需要获取HTML控件file 的绝对路径,而file 本身的函数只提供了获取文件名称,以及大小,临时路径。

以下给出获取绝对路径的详细实现:

<html>

<script>
function chk(){
var fileurl = document.getElementById("file").value;
document.getElementById("hid").value = fileurl;
}
</script>
<body>
<form action="test.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return chk()">
    <input type="file" name="file" id="file" />
    <input type="hidden" name="hid" id="hid">
    <input type="submit" name="button" id="button" value="提交" />
</form>
<p></p>
</body>
</html>

 

test.php

<?php
  echo $_POST["hid"];
?>

你可能感兴趣的:(html,PHP,File,input,action,button)