I can’t seem to validate file upload fields, here’s my code:
<?php
if (isset($_POST['submit'])) {
if ($_POST['uploadFile']) {
echo "File uploaded";
} else {
echo "No file attempted to be uploaded";
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile" />
<input type="submit" name="submit" />
</form>
What is the mistake I’m making?
EDIT
Came up with my own solution, may not be the best but it works:
if (isset($_POST['submit'])) {
$fileUpload = $_FILES['uploadFile'] ['name'];
if (strlen($fileUpload) > 0) {
echo "File uploaded.";
} else {
echo "No File attempted to be uploaded.";
}
}
the superglobal your are looking for is $_FILES.
To make sure a POST request is made you can use the following lines: