Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Handling truncated POST data in php

I have a form with a small number (up to 10) of inputs. One of those inputs is a file upload input. The form layout is as follows:

<form method="post" ...>
<input type="hidden" name="input_no_1" value="value_no_1">
<input type="file" name="input_no_2">
<input type="hidden" name="input_no_3" value="value_no_3">
<button type="submit">send</button>

99.9% of the time this form works fine and I get all the data on the PHP side. However, every once in a while, the POST data gets truncated, and the $_POST variable contains only this:

input_no_1 => value_no_1

The file input and every other input that follows the file input are missing.

This error happens almost exclusively with user agents that contain "Mobile Safari". I suspect that mobile phone users could be using a less reliable network connection and as a result, their request gets aborted and PHP doesn't receive the entire uploaded data.

In my application, I need to know whether the data in the $_POST array is complete or not. I was expecting that if the HTTP server doesn't receive the entire request, I wouldn't even see it from the PHP side.

I am using apache/fpm. The upload_max_filesize and post_max_size are both set to 2G and are nowhere near the size of the uploaded files.

The question: what is the best way to handle incomplete POST data in PHP? Is there a way to prevent these requests from reaching my application, and if not, is there a way to know whether the posted data is complete? I prefer not to add any fields at the end of the form just to find out whether the request is complete or not :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It sounds like this is a case of needing some server side form validation. Assuming the above fields are all required, something like the following might work for you:

if (!isset($_POST['input_no_1'], $_POST['input_no_2'], $_FILES['input_no_2'])) {
    die('Form not filled completely');
} else {
    //process form
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!