我还有其他一些线程,但是仍然无法弄清楚为什么我不能使用以下代码将文件移入文件夹?我还想知道是否存在任何安全问题,例如人们在文件中放置病毒,Windows Defender是否足以阻止这种情况发生?
<?php
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName= $_FILES['file']['tpm_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (!in_array($fileActualExt, $allowed)) {
header("Location: upload.php?upload_form=typeerror");
exit();
} else {
if ($fileError === 1) {
header("Location: upload.php?upload_form=error");
exit();
} else {
if ($fileSize > 500000) {
header("Location: header2.php?upload_form=filesizeerror");
exit();
} else {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header("Location: header2.php?uploadform=success");
exit();
}
}
}
}
答案 0 :(得分:0)
您在tmp_name中输入错误
更改此行
$fileTmpName= $_FILES['file']['tpm_name'];
到
$fileTmpName= $_FILES['file']['tmp_name'];
这将解决您的问题。