fsock - Getting file from POST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lolao
Forum Newbie
Posts: 2
Joined: Wed Jan 30, 2008 8:08 am

fsock - Getting file from POST

Post by lolao »

Hi.

I've been puzzling around with a method, and can't seem to get it working.

What I want to do, is to connect to a page (secure / SSL), login to an account and then get the content of a remote file, which is automatically generated by posting a form.

Most of it works already, but when my script has posted the login (which is successfully carried out) I can't seem to get/download this file I want, from the account front page.
Problem is that the file is generated (XML) when you click on a <button>, which means I don't really know the exact location of the file.
So I've tried submitting/posting the form <button> the same way I've done it with the login, and that seems to be working, but how do I get the content of the generated XML file? Normally, I mean, a download popup would appear if you submitted/posted the <button> through a web browser, but how do I receive the content with my script and maybe place it in a variable ($XML_fileContent).

I've been intensively trying to solve this problem and get it to work for three days now, but really can't seem to figure out a solution. I thought of this forum and I hope that someone can help me out.

[Using fsockopen, no CURL]

Any suggestions? Anyone tried this before who actually made it work?

Help is appreciated! Thanks. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: fsock - Getting file from POST

Post by Christopher »

To cause files to download, rather than display -- use the header() function to set the MIME type, size, etc. Check the documentation for the header() function for examples.
(#10850)
lolao
Forum Newbie
Posts: 2
Joined: Wed Jan 30, 2008 8:08 am

Re: fsock - Getting file from POST

Post by lolao »

Thanks for the answer, but actually the file isn't even displayed. There doesn't seem to be any information indicating the file's path, so I'd have to be able to make a script automatically accept a download dialog OR simply paste the content of the requested file in my document somehow.

Thanks anyway.

Can anyone help any further?
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: fsock - Getting file from POST

Post by Mordred »

If I understand correctly what you're doing, you submit a post form with sockets and raw HTTP, and the form is supposed to return a file download, right? The file contents will come in the body of the HTTP response. Look at the headers sent for details how to obtain the data. Most probably it will be a multipart message, meaning you'll have to correctly manage the parts and then glue the file together. Consult the HTTP/1.1 RFC 2616 (yay, got it from memory, I'm not that rusty after all ;) ) for details. A file download is really not different from a page download.
Post Reply