本文整理汇总了PHP中Attachment::fromId方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::fromId方法的具体用法?PHP Attachment::fromId怎么用?PHP Attachment::fromId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::fromId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public static function create(User $user, $uploaded_filename, $name)
{
// Create a new row in the database for the image
$query = Database::connection()->prepare('INSERT INTO attachment (size, name, created_by, created_at) VALUES (?, ?, ?, ?)');
$query->bindValue(1, filesize($uploaded_filename), PDO::PARAM_INT);
$query->bindValue(2, $name, PDO::PARAM_INT);
$query->bindValue(3, $user->getUserId(), PDO::PARAM_INT);
$query->bindValue(4, time(), PDO::PARAM_INT);
if (!$query->execute()) {
throw new Exception('Unable to create attachment.');
}
// Get the image that we just created
$attachment = Attachment::fromId(Database::connection()->lastInsertId());
if (is_uploaded_file($uploaded_filename)) {
if (!move_uploaded_file($uploaded_filename, self::getStoragePath($attachment->getAttachmentId()))) {
$attachment->delete();
throw new Exception('Unable to move attachment into place.');
}
} else {
if (!rename($uploaded_filename, self::getStoragePath($attachment->getAttachmentId()))) {
$attachment->delete();
throw new Exception('Unable to move attachment into place.');
}
}
//$imagick = new Imagick();
//$imagick->readimage(self::getStoragePath($image->getId()));
//$imagick->setimagetype('png');
//$imagick->writeimage();
return $attachment;
}
示例2: delete_attachment
function delete_attachment()
{
Auth::checkLoggedIn();
$entry = Entry::fromId(Input::get('entryid'));
$attachment = Attachment::fromId(Input::get('attachmentid'));
// Make sure this user can edit the entry
if (!$entry->canEdit(Auth::getUser())) {
throw new Exception('You cannot edit this entry.');
}
// Make sure the attachment belongs to the entry
$attachments = $entry->getAttachments();
$found = false;
foreach ($attachments as $curAttachment) {
if ($curAttachment->getAttachmentId() == $attachment->getAttachmentId()) {
$found = true;
break;
}
}
if (!$found) {
throw new Exception('The requested attachment does not belong to the entry given.');
}
// Now delete the attachment
$attachment->delete();
// We have to manually sync since the attachment isn't part of the entry technically
$entry->changed();
}
示例3: setAvatar
/**
* Sets the avatar for this user given the attachment it is.
* @param Attachment $attachment
*/
public function setAvatar(Attachment $attachment)
{
// Make sure the attachment is an image
if ($attachment->getAttachmentType() != Attachment::ATTACHMENT_TYPE_IMAGE) {
throw new Exception('Avatars must be images.');
}
// Turn the image into a png
$attachment->convertToPNG();
// Turn the new attachment into a thubmnail
$attachment->convertIntoThubmnail();
// See if we need to delete an old one
if ($this->hasAvatar()) {
$oldAvatar = Attachment::fromId($this->getAvatarAttachmentId());
$oldAvatar->delete();
}
// Update the database
$query = Database::connection()->prepare('UPDATE user SET avatar_attachmentid = ? WHERE userid = ?');
$query->bindValue(1, $attachment->getAttachmentId(), PDO::PARAM_INT);
$query->bindValue(2, $this->getUserId(), PDO::PARAM_INT);
$query->execute();
// Update the local value
$this->row['avatar_attachmentid'] = $attachment->getAttachmentId();
}