本文整理汇总了PHP中Avatar::CreateFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP Avatar::CreateFilename方法的具体用法?PHP Avatar::CreateFilename怎么用?PHP Avatar::CreateFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Avatar
的用法示例。
在下文中一共展示了Avatar::CreateFilename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Exception
### Validate avatar extension
$extension = Functions::GetExtension($_FILES['upload']['name']);
if (!in_array($extension, array('gif', 'png', 'jpg', 'jpeg'))) {
throw new Exception(Language::GetText('error_uploadify_extension'));
}
### Validate image data
$handle = fopen($_FILES['upload']['tmp_name'], 'r');
$image_data = fread($handle, filesize($_FILES['upload']['tmp_name']));
if (!@imagecreatefromstring($image_data)) {
throw new Exception(Language::GetText('error_uploadify_extension'));
}
### Change permissions on avatar & delete previous IF/APP
try {
Filesystem::Open();
$avatar_path = UPLOAD_PATH . '/avatars';
$save_as = Avatar::CreateFilename($extension);
Avatar::SaveAvatar($_FILES['upload']['tmp_name'], $extension, $save_as);
// Check for existing avatar
if (!empty($user->avatar)) {
Avatar::Delete($user->avatar);
}
Filesystem::SetPermissions("{$avatar_path}/{$save_as}", 0644);
Filesystem::Close();
} catch (Exception $e) {
App::Alert('Error During Avatar Upload', $e->getMessage());
throw new Exception(Language::GetText('error_uploadify_system', array('host' => HOST)));
}
### Update User
$user->Update(array('avatar' => $save_as));
Plugin::Trigger('update_profile.update_avatar');
// Output success message