473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jun 27 '08 #1
3 6030
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
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
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.-.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,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SamMan | last post by:
I am fairly new to PHP programming, and I'm trying to get my head around this one... I have a form that I am doing validation on via PHP within the same page (form.php), so if there is an error,...
5
by: lucanos | last post by:
Hey All, I'm having trouble trying to create a PHP file which will generate a multipart email message (containing both an HTML formatted part and a Plain Text formatted part). I have Googled...
1
by: Luca Arena | last post by:
Hi, I would like to know if it is possible to call the php parser from a Win32 program (e.g. a VB or C++ program), WITHOUT calling the commandline php.exe utility. I mean, is there any "php_parse"...
1
by: zoltix | last post by:
Hi, How to retrieve a value in in an aspx page? Normally it is easy, drag and drops the textarea in aspx page and it is work. But in this case, I generate the html code manually () and put as...
2
by: Glenn | last post by:
hello: I am working through "Beginning PHP5 Web Development", by WROX, and I am having trouble sending HTML email messages in one application. The email goes through, but is displayed only as...
4
by: yoram.ayalon | last post by:
Hi, I need to create a multipart request to UPS manifest upload electronic service. UPS wants the request to consist of a series of headers and bodies, and its not clear how can I use the...
5
by: MikeR | last post by:
I have an html page which submits form data to an asp page. If I use the get method, the data can be displayed in the receiving page using request.querystring. I'd like to use the post method so...
2
ak1dnar
by: ak1dnar | last post by:
Hi, please help me on this. Here i am having a simple form that consist with name and email fields and both are required fields. i am going to validate this inputs using validate.php. but since i...
2
by: madmak | last post by:
Hi, I am a noob with PHP and need some asistance regarding PHP and lotus notes. I am trying to create a multipart message in PHP to send mail via lotus notes. Here is the code snippet. ...
4
by: Mani | last post by:
Hi Here is my code snippet: <?php error_reporting(E_ERROR | E_PARSE); ?> <html> <body> <form action = "<?php$_SERVER?>" method = "GET" >
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.