Automatic file upload [closed]

-4

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.

    
asked by anonymous 30.06.2014 / 16:34

3 answers

1

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.

    
30.06.2014 / 16:43
0

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.

    
30.06.2014 / 16:53
0

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 first step is to upload automatically when the user selects a file. The file is written to a temporary location and linked to the user's session with some identifier related to the current form.
  • After submitting, I update the form showing an item with the filename and an option to remove it. The file (s) already submitted should be listed through the saved items as described in the previous item.
  • When the form is effectively submitted I check if there are one or more "temporary" files, including their information in some template table and moving the files to the definitive directory.
  • 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.

        
    30.06.2014 / 22:36