note 99340 added to book.curl

From: Date: Wed, 11 Aug 2010 20:26:17 +0000
Subject: note 99340 added to book.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-171584@lists.php.net to get a copy of this message
to pyromus at gmail dot com some help for uploading files <?php class cURL { /*your class funcs and vars*/ function postFile($url, $data, & $info = NULL) { $process = curl_init($url); curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); curl_setopt($process, CURLOPT_HEADER, 1); curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file); if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file); curl_setopt($process, CURLOPT_ENCODING, $this->compression); curl_setopt($process, CURLOPT_TIMEOUT, 30); if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); curl_setopt($process, CURLOPT_POST, 1); curl_setopt($process, CURLOPT_POSTFIELDS, $data); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($process, CURLINFO_HEADER_OUT, 1); // need for kill expectation for code 100-continue curl_setopt($process, CURLOPT_HTTPHEADER, array('Expect:')); $return = curl_exec($process); $info = var_dump(curl_getinfo($process, CURLINFO_HEADER_OUT)); curl_close($process); return $return; } } ?> how to use <?php // save original headers if need // $original_headers = $ch->headers; $ch->headers[0] = 'Accept: application/xml,application/xhtml+xml,'; $ch->headers[0] .= 'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'; // need for file transfering $ch->headers[2] = 'Content-type: multipart/form-data'; // $ch->compression = 'none'; // optional $ch->postFile($host, array('file' => '@path/to/file.etc'), $info); // do not forget '@' before path to file // $info - array of sent headers, information 'bout curl sent data ?> ---- Server IP: 69.147.83.197 Probable Submitter: 178.66.49.172 ---- Manual Page -- http://www.php.net/manual/en/book.curl.php Edit -- https://master.php.net/note/edit/99340 Del: integrated -- https://master.php.net/note/delete/99340/integrated Del: useless -- https://master.php.net/note/delete/99340/useless Del: bad code -- https://master.php.net/note/delete/99340/bad+code Del: spam -- https://master.php.net/note/delete/99340/spam Del: non-english -- https://master.php.net/note/delete/99340/non-english Del: in docs -- https://master.php.net/note/delete/99340/in+docs Del: other reasons-- https://master.php.net/note/delete/99340 Reject -- https://master.php.net/note/reject/99340 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171584) next »