Note that there are some explanatory texts on larger screens.

plurals
  1. POuserland multipart/form-data handler
    primarykey
    data
    text
    <p>I'm looking for a drop-in include script / class that dissects <code>multipart/form-data</code> and fills up <code>$_POST</code>(+raw) and <code>$_FILES</code> from it. Usually PHP does that itself. But because the automatic handling is insufficient for me and makes <a href="http://php.net/manual/en/wrappers.php.php" rel="nofollow noreferrer"><code>php://input</code></a> inaccesible<sup><a href="https://stackoverflow.com/questions/1361673/get-raw-post-data">[1]</a></sup> I'll probably be using something like this to prevent that:</p> <blockquote> <p><code>RewriteRule .* - [E=CONTENT_TYPE:noparsing/for-you-php]</code><br> <a href="https://serverfault.com/questions/257735/rewriterule-e-content-typefoo-bar-has-no-effect-on-apache-mod-php">Does not work. Actual solution requires mod_headers and <code>RequestHeader set</code>...</a></p> </blockquote> <p>The extracting procedure might not be that complex. But I'd rather use a well-tested solution. And foremost I would prefer an implementation that uses <code>fgets</code> for splitting, and mimics the <code>$_FILES</code> handling closely and efficiently. Finding the end of binary payloads would seem rather tricky to me, in particular when you have to strip off <code>\r\n</code> but might encounter clients that only send <code>\n</code> (not allowed, but possible).</p> <p>I'm certain something like this exists. But I'm having a hard time googling it. Does anyone know an implementation? (PEAR::mimeDecode can be hacked to get sort of working for form-data, but is a memory hog.)</p> <p>The use case in short: need to preserve the raw field names (including whitespace and special characters), for logging, but can't avoid file uploads always.</p> <hr> <p>For decorative purposes, that's how a POST request looks:</p> <pre><code>POST / HTTP/1.1 Host: localhost:8000 Content-Length: 17717 Content-Type: multipart/form-data; boundary=----------3wCuBwquE9P7A4OEylndVx </code></pre> <p>And after a <code>\r\n\r\n</code> sequence the multipart/ payload follows like this:</p> <pre><code>------------3wCuBwquE9P7A4OEylndVx Content-Disposition: form-data; name="_charset_" windows-1252 ------------3wCuBwquE9P7A4OEylndVx Content-Disposition: form-data; name=" text field \\ 1 \";inject=1" text1 te twj sakfkl ------------3wCuBwquE9P7A4OEylndVx Content-Disposition: form-data; name="file"; filename="dial.png" Content-Type: image/png IPNG Z @@@MIHDR@@B`@@B;HF@@@-'.e@@@AsRGB@.N\i@@@FbKGD@?@?@? ='S@@@ @@@GtIMEGYAAU,#}BRU@@@YtEXtComment@Created with GIMPWANW@@ @IDATxZl]w| </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload