POST返回文件的空值

I am trying to upload an image using php and pdo. Here is my form

<form action="action.php" class="w3-container" method="post" enctype="multipart/form-data">
 <p>  <label>Image Upload</label>
     <input type="file" name="st_im"></p>
 <input type="submit" value="Submit" class="w3-btn w3-blue">
<input type ="hidden" name="submitted" value="TRUE">

And here's is my php file

if (isset($_POST['submitted'])) {
$errors = array(); 

$imgFile = $_FILES['st_im']['name'];
$tmp_dir = $_FILES['st_im']['tmp_name'];
$imgSize = $_FILES['st_im']['size'];
if (empty($_POST['st_im'])) {
$errors[] = 'you forgot the picture!';
}else{

$upload_dir = 'uploads/'; // upload directory

$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension

 // valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions

 // rename uploading image
$st_im = rand(1000,1000000).".".$imgExt;
}
 if(in_array($imgExt, $valid_extensions)){
// Check file size '5MB'
 if($imgSize < 5000000)    {
 move_uploaded_file($tmp_dir,$upload_dir.$st_im);
 }
 else{
 $errors[] = "Sorry, your file is too large.";
 }
 }
 else{
 $errors[] = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
 }
 if (empty($errors)){
 $stmt1=$conn->prepare("INSERT INTO magazia (st_img) VALUES (:st_im)");
 $stmt1->bindParam(':st_im', $st_im, PDO::PARAM_STR);
 $st_im= $st_im;
 $stmt1->execute();

After submiting the form I get the error: "you forgot the picture" which means that the (st_im) is null. I am stack here for about 2 hours

What I am missing?

Thanks in advance

There is no $_POST['st_im']. As you have correctly used in the lines before that, the information about the upload is stored in $_FILES['st_im'].

So you should check for this instead:

if ($_FILES['st_im']['error'] != UPLOAD_ERR_OK) {
   // Upload error
   $errors[] = 'you forgot the picture!';
}else{