Manually Calling PHP's request parser for multipart/form-data?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hey all,

OK I'm not much of a PHP programmer; but needs must as they say.  I
have written AJAX file upload system that uses a PERL CGI script so
that a PHP script can get the progress (nifty progress bar).
Everything works great; except that currently I'm not decoding the
POST in PERL; so the data file being written is the actual raw form
data (multipart/form-data) with parameters and file content.

I know that when you make a post to PHP; it's little request wrapper
parses this for you into the $_FILES array.  How can I read a file
(the raw form data) and feed it to that parser?  I don't seem to be
able to just call SomeObject.parseMe() :)

Suggestions?  I'd rather not; but one idea for a hack I had was to
actually open a URL stream to myself (PHP script) and manually send
the contents of that file to myself (should recreate the POST from the
form) - but that seems rather bad; especially for larger files.



Re: Manually Calling PHP's request parser for multipart/form-data? wrote:
Quoted text here. Click to load it

 From your update, I have absolutely NO IDEA what you're trying to do.

It's hard to help someone when they aren't detailed and specific.

What you have here is like telling a carpenter "build me a house".

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Manually Calling PHP's request parser for multipart/form-data? wrote:

Quoted text here. Click to load it

If you know how the CGI model was designed, you know that the process
serving the request gets all the POST data via standard input
(AKA "stdin").

So, your question becomes "How do I get all the data that PHP received
through standard input, without the parser that sets up $_FILES and so gets
in the way?"

The answer resides in one of the last chapters of the PHP manual. Go there,
search for fopen() wrappers, search on how to get to stdin, stdout and
stderr. If you actually have worked with low-level CGI handling, it should
pose no match for you.

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"kill -9 needs no justification!"
                               -- BOFH

Re: Manually Calling PHP's request parser for multipart/form-data?

Hey Iv=E1n,

Thank you for the suggest; I'll go dig through there.  However, my
question isn't really how do I get all the data that PHP received.

I wrote a PERL script to handle the file uploads.  My multipart/form-
data form actually posts to that script aka (action=3D./upload.cgi).
This PERL script saves the actual RAW form data coming in to a file.
Then, on the users WWW page there is an AJAX "check status" call every
"x" ms.  This call checks the file size of that raw file and compares
it to the expected size (which the PERL script also saves in a
"metric" file).   One the file is completely uploaded; the PHP script
tries to save the data to a database table.  The data in the file that
PERL saves is like so:

Content-Disposition: form-data; name=3D"assessment_id"
Content-Disposition: form-data; name=3D"attachment_type_id"
Content-Disposition: form-data; name=3D"assessment_attachment";
Content-Type: text/plain
test data here
Content-Disposition: form-data; name=3D"note"

You can see it's just standard boundary multipart data.  So now that
file is is comlplete; a PHP script gets kicked off to read this "raw"
data and store sore the "data part" of it to the database.  So; in PHP
I need to be able to parse this data.  I can write a parser I guess
it's just boundary delineated with \r\n etc etc; but I thought PHP
might have a standard way I should be doing this.


On Jun 13, 7:58=A0pm, Iv=E1n S=E1nchez Ortega <ivansanchez-...@rroba-> wrote:
Quoted text here. Click to load it

Site Timeline