/ Published in: PHP
Here is how to upload an attachment to a CouchDb document using PHP and cURL.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * 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) { $fullpath = self::$url.$path.$filename.'?rev='.$rev; CURLOPT_URL => $fullpath, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'PUT', "Content-Type: ".$content_type, ), CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data ); return $process; } } $test = Couch::upload('/test/upload/', '1-a6eacb015eaedf5bcfb253430281bb65', '/var/www/test/', 'chrome.jpg', 'image/jpeg'); ?>