Example #1
0
 /**
  * @expectedException Exception
  */
 public function testDocumentPutAttachmentWithNoDatabaseOption()
 {
     $attachment = new stdClass();
     $attachment->name = CouchDBTestConstants::kAttachmentName1;
     $attachment->path = $this->pathForResource(CouchDBTestConstants::kAttachmentFilename1);
     $couchdb = new CouchDB();
     $couchdb->put_attachment($attachment);
 }
 *    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 *    PURPOSE. See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package Sample 
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2009 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
$document_id = 'target_documnet_id';
$document_revision = 'revision_id';
$attachmentName = 'avatar';
$attachmentPath = '/path/to/file.png';
$attachment['name'] = $attachmentName;
$attachment['path'] = $attachmentPath;
// The system will currently figure out the content type for gif, jpeg, and png
// if the attachment is not one of those 3 then it will assume binary/octet-stream
// unless the 'content-type' key is provided.
$db->put_attachment($attachment, $document_id);
// avoid an extra lookup by provding the latest document revsion:
// $db->put_attachment($attachment, $document_id, $document_revision);
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 *    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 *    PURPOSE. See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 *    Author: Adam Venturella - aventurella@gmail.com
 *
 *    @package Sample 
 *    @author Adam Venturella <*****@*****.**>
 *    @copyright Copyright (C) 2009 Adam Venturella
 *    @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 *
 **/
/**
 * Sample
 */
require 'couchdb/CouchDB.php';
$newdb = 'newdb';
$options = array('database' => $newdb);
$db = new CouchDB($options);
$attachmentName = 'avatar';
$attachmentPath = '/path/to/file.png';
$attachment['name'] = $attachmentName;
$attachment['path'] = $attachmentPath;
// The system will currently figure out the content type for gif, jpeg, and png
// if the attachment is not one of those 3 then it will assume binary/octet-stream
// unless the 'content-type' key is provided.
$result = $db->put_attachment($attachment);