使用未定义的常量fileError - 在第17行的C:\ xampp \ htdocs \ test \ upload.php中假设'fileError'(这将在未来版本的PHP中引发错误) 上传文件时出错
<?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('jpg', 'jpeg', 'png', 'pdf');
if(in_array($FileActualExt, $allowed)){
if(fileError === 0){
if ($fileSize < 500000000){
$FileNameNew = uniqid('', true).".".$FileActualExt;
$FileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header('Location: index.php?uploadsuccess');
} else {
echo "Your file was too big";
}
} else {
echo "There was an error uploading your files";
}
} else {
echo "You can't upload files of this type";
}
}
?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
解决错误的正确代码是什么?
答案 0 :(得分:0)
尝试更改
if(fileError === 0){
到
if($fileError === 0){