note 30796 deleted from function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:59:10 +0000 |
| Subject: | note 30796 deleted from function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155615@lists.php.net to get a copy of this message | ||
Note Submitter: csnyder at chxo dot com
----
Need to create a POST request that uploads a file?
I spent this afternoon trying to figure out what one looks like, and here is a template that has
been successful for me:
========================
POST /path/to/script.php HTTP/1.0
Host: example.com
Content-type: multipart/form-data, boundary=AaB03x
Content-Length: $requestlen
--AaB03x
content-disposition: form-data; name="field1"
$field1
--AaB03x
content-disposition: form-data; name="field2"
$field2
--AaB03x
content-disposition: form-data; name="userfile"; filename="$filename"
Content-Type: $mimetype
Content-Transfer-Encoding: binary
$binarydata
--AaB03x--
==========================
Note that you have to generate the Content-Length header after you generate the body of the request
(from the first --AaB03x down, including the file data), so the thing to do in practice is to build
the body first, get the strlen(), and then build the headers onto the front of the body.
See RFC1867 - Form-based File Upload in HTML (http://www.faqs.org/rfcs/rfc1867.html) for more info
on the format of "multipart/form-data" posts.
Good luck!