note 30796 added to function.fsockopen
| From: | csnyder at chxo dot com | Date: | Sat, 29 Mar 2003 01:04:48 +0000 |
| Subject: | note 30796 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45966@lists.php.net to get a copy of this message | ||
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!
--
http://www.php.net/manual/en/function.fsockopen.php
http://master.php.net/manage/user-notes.php?action=edit+30796
http://master.php.net/manage/user-notes.php?action=delete+30796
http://master.php.net/manage/user-notes.php?action=reject+30796