By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

thanks!

Jeremy
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
je************@gmail.com wrote:
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.

thanks!

Jeremy
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.
js*******@attglobal.net
==================

Jun 27 '08 #2

P: n/a
je************@gmail.com wrote:

[...]
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?
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.
Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"kill -9 needs no justification!"
-- BOFH
Jun 27 '08 #3

P: n/a
Hey Ivn,

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=./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:

-----------------------------24464570528145
Content-Disposition: form-data; name="assessment_id"
13
-----------------------------24464570528145
Content-Disposition: form-data; name="attachment_type_id"
1
-----------------------------24464570528145
Content-Disposition: form-data; name="assessment_attachment";
filename="SomeTestFile.txt"
Content-Type: text/plain
test data here
-----------------------------24464570528145
Content-Disposition: form-data; name="note"
test
-----------------------------24464570528145--

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.

Jeremy

On Jun 13, 7:58*pm, Ivn Snchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
jeremy.gehr...@gmail.com wrote:

[...]
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?

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.

Cheers,
--
----------------------------------
Ivn Snchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"kill -9 needs no justification!"
* * * * * * * * * * * * * * * *-- BOFH
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.