- To: Julio Cesar Ody <julioody@xxxxxxxxx>, slug <slug@xxxxxxxxxxx>
- Subject: Re: [SLUG] fetching POSTed file
- From: Rob Sharp <rob.sharp@xxxxxxxxx>
- Date: Tue, 8 Feb 2005 17:23:11 +1100
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=ignTXul8aRnYoUDZG2G1BMuLOGGpnqt4KvEL17/s33cy8TH4i1yVjVqOjXuNjuD2dEgMG0EuJOvZhivSvO+hpNSOQ8oMzvN2PR6Rx+274TrvG3wEUE4+IqicP4zVfJQ3wWQ7E2t5+br2vVyCg6PNWKMC7Gv3rOloqjBgmXJtclk=
- Reply-to: rob@xxxxxxxxxxx
This'll help!
---
Multipart form uploads (ie simulating the upload of files from a
browser form) is surprisingly easy, yet hard to find information
on.... hope this changes that.
$postData = array();
//simulates <input type="file" name="file_name">
$postData[ 'file_name' ] = "@test.txt";
$postData[ 'submit' ] = "UPLOAD";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );
//seems no need to tell it enctype='multipart/data' it already knows
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
$response = curl_exec( $ch );
//where test.txt is a file in the same directory!
On Tue, 8 Feb 2005 16:04:29 +1100, Rob Sharp <rob.sharp@xxxxxxxxx> wrote:
> Hi
>
> A good starting point would be the CURL library. You could POST the
> data to the other system, and screen-scrape the response by capturing
> it into a variable.
>
> http://au2.php.net/curl
>
> A little busy at the mo, so cant do you any sample code!
>
> HTH
>
> Rob.
>
>
> On Tue, 8 Feb 2005 15:26:07 +1100, Julio Cesar Ody <julioody@xxxxxxxxx> wrote:
> > Hello all,
> >
> > I'm coding a PHP script that is supposed to present an HTML form to
> > the user, where he can upload a file. However, the form target is a
> > webpage outside of my domain (I really don't have access to it). On
> > normal usage, the uploaded file is processed by this remote script
> > (the form target), and a result page is generated containing a link
> > for downloading the file back.
> > I was thinking about building a script that actually used this as a
> > backend system. I believe it would have to be able to POST the file to
> > the remote script, parse the response page returned to me and get the
> > link to my file's name, and then download it to my own server (where
> > my PHP script is running). The last two steps seem fairly easy.
> > However, I'm just not sure how can I post a file to a PHP script on a
> > server I run, make it upload (again?) to the remote script, capture
> > the response and fetch the file.
> > Any ideas or starting points? Thanks in advance.
> >
> > --
> > Julio C. Ody
> > http://rootshell.be/~julioody
> >
> > -----BEGIN GEEK CODE BLOCK-----
> > Version: 3.12
> > GCS/SS/CC d@ s: a? C++(+++) ULB+++$ P++++ L+++$ !E W++(+++) N+ !o K- !w O- M
> > V- PS+ PE Y+ PGP++(-) t 5 X R+ tv-- b++ DI-- D+ G++ e h r+ y++*
> > ------END GEEK CODE BLOCK------
> > --
> > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
> >
>
> --
> Rob Sharp
>
> e: rob@xxxxxxxxxxx
> w: quannum.co.uk
> j: rob.sharp@xxxxxxxxxx
>
--
Rob Sharp
e: rob@xxxxxxxxxxx
w: quannum.co.uk
j: rob.sharp@xxxxxxxxxx