- 上传前台文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
文件:<input name="userfile" type="file" />
<input type="submit" name="上传文件" />
</form>
</body>
</html>
- php代码部分
<?php
$uploaddir = './uploads/';
$uploadfile = $uploaddir.basename($_FILES['userfile']['name']);
$name = $_FILES['userfile']['name'];
$ext = substr(strrchr($name,'.'),1);
$allow_type = ['jpg','png','gif','zip','jpeg','bmp'];
$allow = false;
foreach($allow_type as $v){
if($ext == $v){
$allow = true;
}
}
$allow or die("不允许上传该类型");
echo "<pre>";
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)){
echo "上传文件成功\n";
}else{
echo "上传文件失败\n";
}
echo "更多信息";
print_r($_FILES);
print "</pre>";