note 89080 added to function.stream-context-create

From: Date: Fri, 20 Feb 2009 17:56:15 +0000
Subject: note 89080 added to function.stream-context-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-150899@lists.php.net to get a copy of this message
I found the following code worked for me for POSTing some binary data to a remote server. I am putting it here since I could not find a quick solution to this by 'googling' or looking through this documentation. Disclaimer: I have no idea if this a 'good' solution, since I'm new to PHP, but it may just suit your needs as it did mine. I am assuming bad things will happen with very large files since the entire file is read into $fileContents. I am using PHP 5.2.8. $fileHandle = fopen("someImage.jpg", "rb"); $fileContents = stream_get_contents($fileHandle); fclose($fileHandle); $params = array( 'http' => array ( 'method' => 'POST', 'header'=>"Content-Type: multipart/form-data\r\n", 'content' => $fileContents ) ); $url = "http://somesite.somecompany.com?someParam=someValue"; $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); $response = stream_get_contents($fp); ---- Server IP: 216.235.13.26 Probable Submitter: 129.42.208.186 ---- Manual Page -- http://www.php.net/manual/en/function.stream-context-create.php Edit -- https://master.php.net/note/edit/89080 Del: integrated -- https://master.php.net/note/delete/89080/integrated Del: useless -- https://master.php.net/note/delete/89080/useless Del: bad code -- https://master.php.net/note/delete/89080/bad+code Del: spam -- https://master.php.net/note/delete/89080/spam Del: non-english -- https://master.php.net/note/delete/89080/non-english Del: in docs -- https://master.php.net/note/delete/89080/in+docs Del: other reasons-- https://master.php.net/note/delete/89080 Reject -- https://master.php.net/note/reject/89080 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150899) next »