Home > other >  Potential issue with file uploads via Chrome?
Potential issue with file uploads via Chrome?

Time:11-01

So I have a working file upload system on my site.... and it basically works every single time anyone uses it. There have been a few cases where users have submitted data and the page has basically returned a PHP UPLOAD_ERR_NO_FILE, but I've only seen this occur via the Chrome browser (recent versions being 94.0.4606.81 & 95.0.4638.54). Every time I try in Chrome myself it works fine, and these users never really communicate there is a problem and don't come back, I just see it in the logs that it's happened. I'm just wondering whether anyone knows of any browser extensions or anything which may be interfering in this from Chrome's point of view? i.e. wiping the files before they're sent?

I don't really use Chrome so I'm not that aware of how it functions, but I'm assuming it doesn't really handle things that different to the other browsers in terms of HTTP headers and data??

I just find it bizarre that someone would try to upload a file, fill out all the other input fields, press submit but not actually upload a file. For the record:

  1. This is NOT via AJAX, it's a direct form upload
  2. This is the only place that catches this specific error so there's no other explanation as it's a very specific error I'm getting
  3. It's well below the MAX_FILE_SIZE and POST_MAX_SIZE in php.ini so it's not even like the server are wiping them, which is impossible anyway because I wouldn't even get this far in the script
  4. It's always in the same place and on the same line every time. I have two file uploads, one is optional (preview image) and the other is mandatory (zip). It's not even like they're uploading a zip in the preview because the preview is validated first with no errors.....
  5. It does however happen with different download categories
  6. It can't be caching because each request appends the timestamp to the submission URL

CodePudding user response:

UPLOAD_ERR_NO_FILE

Value: 4; No file was uploaded. (ref)

Is that there was no file.

Like this form submitted without selecting a file:

<form method="post" enctype="multipart/form-data">
  <input type="file" name="file">
  <input type="submit"> <input type="reset"> 
</form>

As it's client side, there can be client side scripts that remove the file when the form is submitted. For example:

document.forms[0].file.value = ""

Magic? Bizarre? Likely not, your form handling should deal with it. E.g. display the form again, mark the inputs where data was missing / wrong, give an accessible error message and fill all form-fields with the submitted value so that the user can fix any errors easily and must not completely re-fill the form nor clears the whole form with the reset button.

You can also mirror the error handling on the client side with client-side scripts so that the feedback for the user is even faster and you spare a round-trip to the server for common user-input-errors.

  • Related