Error uploading file using type="file"

2

I have a big problem that is quite strange, I have a input type="file" on my website, in which users can upload a photo of a document. What happens to me is that sometimes from a mobile, when using the input to upload a photo from the camera, sometimes it is uploaded correctly and sometimes not.

The problem is not when completing form and uploading the document to the server, but at the time of selecting the file and leaving it within input . When I make the photo and I accept / send, instead of putting the name of the file in input , I refresh the page, I leave the small code with input .

<p>
  <form id="carga_archivo" name="carga_archivo" enctype="multipart/form-data" action="uploader.php" method="POST" style="padding: 0; margin-top: 20px;">
  
     <input type="file" id="file-input" name="uploadedfile">
     <input type="text" name="id" value="<?php echo $row['id']; ?>" style="display: none;">
     <input id="albaran" name="albaran" type="number" placeholder="Nº de Albarán" style="text-align: center; height: 50px;" required>
     <input type="submit" value="SUBIR Y COMPLETAR AVISO" style="background:#1e81e6; color:white;font-weight: bold;height: 45px;" />
     
   </form>
</p>
    
asked by Tefef 19.01.2018 в 16:29
source

2 answers

2

I have a simple suggestion:

  • Locate an ajax caller that passes a notification to the server indicating that you are going to send a photo (which is about to be taken)
  • when the server responds to the notification, the registered method for .success or .done opens the camera as your click did.
  • When the server receives the request for the page to be reloaded, it finds a flag indicating that there is a midway process.
  • A modified page is then served whose onload event is registered and launches the function that completes the task and that could not be completed by recharge.
  • When the page is sent and saved it deletes the flag and its response reloads the original version, without onload to avoid problems of failed reiterations.
  • I hope the suggestion will help.

    Ah I forgot, sometimes it's a cache problem: sometimes it reads in the other one.

        
    answered by 18.06.2018 в 06:18
    1

    Unfortunately it is a problem of the mobile device and not of your application, so there is little you can do to solve it. I found this question in SO in English asking about the same, and it seems that the scenario is this:

  • You have the page loaded and you want to use the camera application (or any other) to select a file to upload it.
  • This second application happens to be in the foreground, while the browser is in the background, waiting.
  • Perhaps because this application occupies a lot of RAM or simply because the OS decides that it has to free memory, the applications in the background close.
  • You have selected the photo and it is sent to the browser application. The browser opens, remembering the page (the URL) but not the content of it, which refreshes, losing the data entered so far.
  • Therefore there is not much you can do to solve it, there are complaints from users that happen today even with mobile phones with 8GB of RAM.

        
    answered by 19.01.2018 в 17:08