本文整理匯總了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