PHP midgard object method create_attachment
Creates new attachment.
midgard_attachment create_attachment([name], [title], [mimetype]);
This method takes three arguments:
- name, string with unique name for attachment
- title, string title for attachment
- mimetype, string mimetype for attachment
name must be uniqe among all attachments attached to object. Following Midgard convention, there's no possibility to create two attachment objects with the same name, except empty name.
Note, that all arguments are optional, as there might be a need to create attachment ( with empty name and title ) first and update its properties conditionally.
Returns newly created midgard_attachment object, or NULL on failure.
Example
<?php
try {
$topic = new midgard_topic($guid);
} catch (Exception $e) {
echo $e->getMessage();
}
$att = $topic->create_attachment("thumbnail");
if($att)
{
$att->title = "The picture to show";
$att->mimetype = "image/jpeg";
$att->update();
}
?>
Read about midgard_blob::write_content if you need to create attachment and its file.
