PHP文件上传主要两个步骤:
1.首先前端html写好文件表单上传网页
2.在前端点提交时,web服务器php脚本通过超全局变量$_FILES和一个move_uploaded_file函数搞定
前端html如下:
<meta charset="utf-8"> <title>文件上传</title>
2.服务器php脚本upload.php代码如下:
<?phpif (move_uploaded_file($_FILES['uploadpic']['tmp_name'], './fileupload/'.$_FILES['uploadpic']['name'])){ echo "ok"; }else { echo "fail";}
array ( 'uploadpic' => array ( 'name' => '1客栈首页.jpg', 'type' => 'image/jpeg', 'tmp_name' => 'C:\\Windows\\Temp\\php3F1C.tmp', 'error' => 0, 'size' => 1706919, ),)ok