Revision: 24663
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 8, 2010 04:29 by stephanepericat
Initial Code
/** * author: Stephane P. Pericat * date: 2010-03-08 */ <?php class Couch { static $url = "http://localhost:5984"; static function upload($path, $rev, $filepath, $filename, $content_type) { $ch = curl_init(); $fullpath = self::$url.$path.$filename.'?rev='.$rev; $data = file_get_contents($filepath.$filename); $options = array( CURLOPT_URL => $fullpath, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array ( "Content-Type: ".$content_type, ), CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data ); curl_setopt_array($ch, $options); $process = curl_exec($ch); curl_close($ch); return $process; } } $test = Couch::upload('/test/upload/', '1-a6eacb015eaedf5bcfb253430281bb65', '/var/www/test/', 'chrome.jpg', 'image/jpeg'); var_dump($test); ?>
Initial URL
Initial Description
Here is how to upload an attachment to a CouchDb document using PHP and cURL.
Initial Title
Upload an attachment to CouchDb
Initial Tags
curl, php
Initial Language
PHP