php中文件上传的实现
1.上传代码:利用html中的form表单,浏览选择文件。
<form id="upload-form" action="" method="post" enctype="multipart/form-data" name="form">
<div style="float:left;width:100%">
<input id="fname" type="text" tabindex="1" style="float:left;width:80%;height:40px;border:1px solid #34495E"/>
<input id="up_file" name="up_file" type="file" style="display:none" required="required" onchange="document.getElementById('fname').value=this.value"/>
<input type="button" name="submit" style="float:left;width:10%;height:40px;border:1px solid #34495E;background-color:#34495E;color:#ffffff" value="浏览" onclick="select_file();"/>
<input type="submit" name="submit" style="float:left;width:10%;height:40px;border:1px solid #34495E;background-color:#34495E;color:#ffffff" value="上传"/>
</div>
</form>
2.点击submit后,触发php代码,进行上传处理
<?php
$destation = 'E:/userupload/';
if(!empty($_FILES['up_file']['name'])){
$fileinfo = $_FILES['up_file'];
move_uploaded_file($fileinfo['tmp_name'],$destation.$fileinfo['name']);
}
?>