note 99340 deleted from book.curl by danbrown

From: Date: Wed, 11 Aug 2010 20:27:58 +0000
Subject: note 99340 deleted from book.curl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171585@lists.php.net to get a copy of this message
Note Submitter: markhost at yandex dot ru ---- 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 ?>

« previous php.notes (#171585) next »