我正在编写一个插件,该插件允许从管理区域上传文件(.txt,.xml)。这是管理页面中的代码:
HTML
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" name="submit">UPLOAD</button>
</form>
PHP (upload.php)
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.',$fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('txt','zip','rar','xml');
if (in_array($fileActualExt, $allowed)){
if ($fileError === 0) {
if ($fileSize < 500000) {
$fileNameNew = uniqid('',true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName,$fileDestination);
} else {
echo "Your file is too big!";
}
} else {
echo "There was a problem uploading your file!";
}
} else {
echo "You can't upload files of this type!";
}
}
可以这样吗?