I need to make sure that when updating the page, my <input type="file">
element will already be loaded with the files that will be saved in the database, remembering that the files will have the same name.
I need to make sure that when updating the page, my <input type="file">
element will already be loaded with the files that will be saved in the database, remembering that the files will have the same name.
Do you want the form to be self-submitted? If this is it:
<form id="formulario" method="post" enctype="multipart/form-data">
<input type="file" onchange="formulario.sumbit()" name="arquivos[]" multiple/>
</form>
The spell is in onchange="formulario.submit()"
. It executes the function when the value of input
is changed.
The name
attribute with []
at the end serves for ease in handling the data in the backend .
The multiple
attribute is used to tell the browser to accept multiple files.
The input type = file field can not be loaded again with the files that are in the database, you must view the files in another way. the file type field is not like a text field that you can add text to a value to display to the user.
For example: You uploaded an image in the input file, sent it to the bank. In your bank you saved the path of the image that was uploaded on the server. At the time of editing this image you do not load its data in your input file, you display it in an the input file field is blank.
Forms with events and uploads (single or multiple) are a problem from the point of view of usability.
Due to security restrictions, you can not set the name of the file to be sent programmatically. So, if it is necessary to update the form without Ajax, the file will be sent or "lost".
So what I usually do is unlink attachments from the rest of the form:
The directory with temporary files should be cleaned from time to time, excluding files from abandoned sessions. You can use some criterion related to the date of the file for this, for example, excluding files older than 1 day.