473,778 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.pars eMe() :)

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 6053
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.pars eMe() :)

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*******@attgl obal.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="assessmen t_id"
13
-----------------------------24464570528145
Content-Disposition: form-data; name="attachmen t_type_id"
1
-----------------------------24464570528145
Content-Disposition: form-data; name="assessmen t_attachment";
filename="SomeT estFile.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
735
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, a message will show to the user above the form. If all goes well, I would like to call a processing script that I have already set up and working to format the users response and send it out to a specified e-mail... I'll call it processing.php ...
5
14237
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 for it, and found previous entries in Google Groups, but I just can't get it to work. My PHP File contains the following:
1
2354
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" function, exported by the php5ts.dll, which I can declare in my Win program and then call to parse a php script? Thanks in advance Luca
1
7061
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 literal html in the aspx page. How to do for retrieving the value in my textarea without define a variable (runnat server) in c# code? I thought this code retrieve all controls and value in all tag inside the Form tag, it is not the case.
2
2064
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 text/plain not text/html. Here are the headers: Date: Wed, 25 Oct 2006 14:05:03 -0400 To: XXX@gmail.com Subject: Please Confirm your postcard
4
5325
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 HttpWebRequest object to do this. there is the Headers collection, but I don't think it will give me the control we need. is there a low-level way to create the entire stream and attach to the object before posting ?
5
3759
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 the data isn't on the URL. <form method="POST" ENCTYPE="multipart/form-data" Action="..\og\cc.asp"> <input type="text" name="T1" size="20"><P> <input type="submit" value="Submit" name="B1"> </form> Below is the script on the rreceiver.
2
3077
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 am since i am using responseText object i couldn't display the error message for corresponding fields. That means if name is blank error should appers in <span id="output_name"> if email is blank error should appers in <span id="output_email"> ...
2
6309
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. <?php ---some code here -- $session_notes = new COM("Lotus.NotesSession"); $session_notes->Initialize("<password>");
4
1924
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
9629
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10127
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7474
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.