I have an form that I submit which has among other inputs, an image input like so:
<label id="labelEnviarImagem" for='enviarImagem'>Choose a file »</label><br>
<input required type="file" name="productFile" id="enviarImagem">
My problem is the following:
Sometimes, other inputs from the form won't be valid, and the PHP will return the user to the form page while saving the previous values on the $_SESSION
so the user has the form pre-filled and will be able to fix their mistakes without having to re-type everything. How can I do the same for the image?
I've tried to save the image on the session and then pass that as the value to the input, but obviously it didn't work.
$_SESSION["dadosProduct"]["img"] = $_FILES['productFile']['tmp_name'];
<input required type="file" name="productFile" value="<?php echo isset($_SESSION['dadosProduct']) ? $_SESSION['dadosProduct']['name'] : ""; ?>" id="enviarImagem">
My question is: I can save the information when the input type is text/number by using the $_SESSION
easily, how can I do the same when the input type="file"
?