你好我有一个简单的PHP表单,它有一个输入文件字段和上传按钮我想要做的是当点击按钮时文件应该上传到一个名为uploads的目录但是它不会在这里工作是代码。
<?php
if(isset($_FILES['uploadfilefield']))
{
$uploadName = $_FILES['uploadfilefield']['name'];
$uploadTmp = $_FILES['uploadfilefield']['tmp_name'];
$uploadType = $_FILES['uploadfilefield']['type'];
$uploadName = preg_replace("#[^a-z0-9.]#i","",$uploadName);
if(!$uploadTmp)
{
die("no file Selected,Please Upload Again");
}
else
{
move_uploaded_file($uploadTmp, "uploads/$uploadName");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
<style>
body
{
margin: 0;
padding: 0;
background: #CCC;
}
.fileuploadholder
{
width : 400px;
height: 200px;
margin: 60px auto 0px auto;
border: 1px solid #CCC;
background: #FFF;
padding: 20px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="fileuploadholder">
<form method="post" enctype="multipart/form-data" action="index.php">
<input type="file" name="fileupload" id="uploadfilefield">
<input type="submit" value="Upload" id="uploadbutton">
</form>
</div>
</body>
</html>
的照片
,这是在目录
中