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

This is a discussion on Manually Calling PHP's request parser for multipart/form-data? within the PHP Language forums, part of the PHP Programming Forums category; Hey all, OK I'm not much of a PHP programmer; but needs must as they say. I have written ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-13-2008
jeremy.gehring@gmail.com
 
Posts: n/a
Default Manually Calling PHP's request parser for multipart/form-data?

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
Reply With Quote
  #2 (permalink)  
Old 06-14-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Manually Calling PHP's request parser for multipart/form-data?

jeremy.gehring@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.
jstucklex@attglobal.net
==================

Reply With Quote
  #3 (permalink)  
Old 06-14-2008
Iván Sánchez Ortega
 
Posts: n/a
Default Re: Manually Calling PHP's request parser for multipart/form-data?

jeremy.gehring@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
Reply With Quote
  #4 (permalink)  
Old 06-15-2008
jeremy.gehring@gmail.com
 
Posts: n/a
Default Re: Manually Calling PHP's request parser for multipart/form-data?

Hey Iván,

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, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> 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,
> --
> ----------------------------------
> Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
>
> "kill -9 needs no justification!"
> * * * * * * * * * * * * * * * *-- BOFH


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:09 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0