PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Manually Calling PHP's request parser for multipart/form-data?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Manually Calling PHP's request parser for multipart/form-data?

Réponse
 
LinkBack Outils de la discussion
Vieux 13/06/2008, 19h45   #1
jeremy.gehring@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 14/06/2008, 01h46   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 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
==================

  Réponse avec citation
Vieux 14/06/2008, 02h58   #3
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 15/06/2008, 19h14   #4
jeremy.gehring@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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:58pm, 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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h04.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12598 seconds with 12 queries