本文整理汇总了PHP中BuckysUser::updateUserProfileThumbnail方法的典型用法代码示例。如果您正苦于以下问题:PHP BuckysUser::updateUserProfileThumbnail方法的具体用法?PHP BuckysUser::updateUserProfileThumbnail怎么用?PHP BuckysUser::updateUserProfileThumbnail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BuckysUser
的用法示例。
在下文中一共展示了BuckysUser::updateUserProfileThumbnail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeProfileImageAction
public function changeProfileImageAction()
{
global $TNB_GLOBALS;
$data = $_POST;
$token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null;
if (!$token) {
return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')];
}
if (!($userID = BuckysUsersToken::checkTokenValidity($token, "api"))) {
return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')];
}
//Upload photo if it is image type
$tempFile = $_FILES['image']['tmp_name'];
$targetPath = DIR_FS_PHOTO . "tmp";
if (!is_dir($targetPath)) {
mkdir($targetPath, 0777);
//Create Index file
$fp = fopen($targetPath . "/index.html", "w");
fclose($fp);
}
// Validate the file type
$fileParts = pathinfo($_FILES['image']['name']);
//Check the file extension
if (in_array(strtolower($fileParts['extension']), $TNB_GLOBALS['imageTypes'])) {
//Check Image Size
list($width, $height, $type, $attr) = getimagesize($tempFile);
//Check Image Type
if (!in_array($type, [IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG])) {
return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_PHOTO_TYPE)];
}
if ($width * $height > MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT) {
return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_PHOTO_MAX_SIZE_ERROR)];
} else {
$targetFileName = md5(uniqid()) . "." . $fileParts['extension'];
$targetFile = $targetPath . '/' . $targetFileName;
move_uploaded_file($tempFile, $targetFile);
$data['file'] = $targetFileName;
}
} else {
return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_PHOTO_TYPE)];
}
if (BuckysUser::updateUserProfileThumbnail($userID, $data['file'])) {
//Success
$message = buckys_get_pure_messages();
return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => 'SUCCESS', 'MESSAGE' => $message]];
} else {
$error = buckys_get_pure_messages();
return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result($error)];
}
}