RE: [PHP] Multi-Part PostToHost?

2002-07-16 Thread skeller

Just out of curiosity, before I get elbows-deep in this, has anyone does
this already, before I start rewriting the wheel? Using PHP to POST a file
and a few variables to another server's catcher script that is.

> > fputs($fp, "Content-Type: multipart/form-data; boundary=AaB03x\n");
> > fputs($fp, "--AaB03x\n");

> That looks quite reasonable

Thanks Richard.

Reasonable. I'll take that. It's better than "WHAT ARE YOU SMOKING YOU
FREAKING MORON?"

> EXCEPT:
>
> It's *POSSIBLE* that "Aa03x" will be *IN* the document...

Well yes, the only reason I happened to use that particular sentinel was
that I cut-n-pasted the header information. But you're right, a longer, more
complex sentinel would help.

> $myfile = file('/full/path/to/myFile.xml') or die("Could not open
> myFile.xml");
> $myfile = implode('', $myfile);
> $boundary = md5(uniqid(''));
> # Hey, the odds are one in a zillion, but why not?
> while (strstr($myfile, $boundary)){
>   $boundary = md5(uniqid(''));
> }

Ok, had to look that one up :)

uniqid is a new one on me. I've been naming files according to the session
id to prevent overwrites.

> And I think you need a different boundary for *EACH* part of
> the multipart stuff...  But maybe that's just me thinking
> wrongly...

If I understand HTTP 1.0, and I probably don't, you only need to use
seperate identifiers if you're appending more than one file, then you need a
new identifier to delineate the parts of the "FILES" section.












Not 100% accurate because I just wrote that off the top of my head, but
that's pretty much how I understand it. Anyone who knows better is free to
slap me with a trout.

> Other than that, I'm guessing that you *MIGHT* need to
> somehow "escape" the contents of the data...

I was thinking about that. I'm wondering if I can fake CRLF by sending the
ASCII equivalents.

> I dunno if browsers and web-servers expect that data to be
> uuencoded, or base64 encoded

Well, browsers don't matter, since this will all be entirely handled by the
servers. But it's definitely something to consider while I'm dorking around.

> But you're definitely on the right track, and you're down to
> minutia at this point.

Well, considering I didn't get pushed around by the big kids and have my
lunch money taken, I'll assume that I'm not totally dum. I'm guessing what I
should do now is write an upload script and try to simulate the pass and see
how close I am.

Still, I can't imagine I'm the first person trying to do a text file
server-to-server POST. It'd be nice if I could find someone who's already
done something like this. I've been Googling for it the last two days and
have found several people on Usenet and the mailing lists asking about
POSTing XML files to scripts, but nobody who said, "I did it, here's how
it's done."


Thanks again Richard.

~Steve-o


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Multi-Part PostToHost?

2002-07-15 Thread Steve Keller

First, thanks to the people who've helped me so far.

I'm a UI designer who's suddenly found himself responsible for a very large
website that integrates services from no less than four different providers,
and I've been dumped into learning PHP on my own under a heavy deadline.

Anyway, I'm catching data from a form post and writing an XML document out
of it. That's done, the server can process the XML correctly. But, from
there, I need that file to be appended to a POST to a script on another
server for processing. I've tried looking up how this is accomplished, and
Richard Lynch was kind enough to point me in the direction of PostToHost,
which got me off to a jump start on how to find more information.

So now I'm at a point where I need help.

After opening the socket, can I declare a multi-part POST and then start
sending the data? Such as:

fputs($fp, "Content-Type: multipart/form-data; boundary=AaB03x\n");
fputs($fp, "--AaB03x\n");
fputs($fp, "Content-Disposition: form-data; name="variable1"\n");
fputs($fp, "\n");
fputs($fp, "Variable 1 Data\n");
fputs($fp, "--AaB03x\n");
fputs($fp, "Content-Disposition: form-data; name="files";
filename="myFile.xml"\n");
fputs($fp, "Content-Type: text/plain\n");
fputs($fp, "\n");
fputs($fp, "... contents of myFile.xml ...\n");
fputs($fp, "--AaB03x--\n");

And again, I've only been doing PHP a week, so if I'm following a totally
wrong track here, feel free to smack me around.



As always, any help is greatly appreciated.

~Steve-o


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php