How do I POST a file using php?
December 11, 2006 3:34 PM   Subscribe

How do I POST a file using php? Not POSTing to a PHP script but using php to read a file from the file system and POSTing it to another site. The site I am working on doesnt have cURL but fsockopen is available.
posted by Pasa la bola chetu to Computers & Internet (5 answers total)
 
Take a look here.
posted by chrisroberts at 3:40 PM on December 11, 2006


Response by poster: thnx, did see that. I was looking for POSTing a form using 'multipart/form-data' so I can submit files, has anyone else done this? Dont want to redo the wheel.

Also, how about both a POST and a GET, as in

<form action='/formProcessos.php?argv=1' >
<hidden name='field1' value='value1' />
</form>

I see on the server side that such a form would make the form values available under $_GET and $_POST respectively.

thanks
posted by Pasa la bola chetu at 3:51 PM on December 11, 2006


Two things: Make sure your HTML form contains the crucal enctype="multipart/form-data" attribute, and then use the $_FILES superglobal to access the uploaded file data. All of this is explained in the fine manual.
posted by migurski at 4:43 PM on December 11, 2006


"Snoopy is a PHP class that simulates a web browser. It automates the task of retrieving web page content and posting forms, for example."

Snoopy can do this for you.
posted by scottreynen at 5:41 PM on December 11, 2006


I've never coded this sort of thing in php before, but quick google for "php httpclient" gave me this.
posted by david1230 at 5:47 PM on December 11, 2006


« Older The lighthouse ghost   |   Under pressure Newer »
This thread is closed to new comments.