本文整理汇总了PHP中FileHandler::prepareFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::prepareFiles方法的具体用法?PHP FileHandler::prepareFiles怎么用?PHP FileHandler::prepareFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::prepareFiles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_edit
public function action_edit()
{
$lUserData = Input::post('user', null);
$lAvatar = Input::post('avatar', null);
$lDeleteAvatar = Input::post('delete_avatar', null);
if (empty($lUserData)) {
die(json_encode(['status' => 'error', 'message' => 'Empty data for updating user'], JSON_UNESCAPED_UNICODE));
}
$lIsOwner = $lUserData['username'] == $this->current_user['username'];
if ((empty($lUserData['username']) || !$lIsOwner) && !$this->is_admin) {
die(json_encode(['status' => 'error', 'message' => 'Access denied'], JSON_UNESCAPED_UNICODE));
}
$lUserName = $lUserData['username'];
unset($lUserData['username']);
try {
DB::start_transaction();
$lOldData = Auth::get_profile_fields();
if (!empty($lAvatar)) {
$lNewAvatar = FileHandler::prepareFiles($lAvatar, FileHandler::tempFolder());
foreach ($lNewAvatar as $lVal) {
$lUserData['avatar_id'] = Model_Avatars::add(['file_name' => $lVal]);
break;
}
if (!empty($lOldData['avatar_id'])) {
$lToDeleteAvatar = Model_Avatars::getById($lOldData['avatar_id']);
Model_Avatars::delete($lOldData['avatar_id']);
}
}
if (!empty($lDeleteAvatar) && empty($lAvatar)) {
$lOldAvatar = Model_Avatars::getById($lOldData['avatar_id']);
foreach ($lDeleteAvatar as $lVal) {
if ($lVal != $lOldData['avatar_id']) {
break;
}
$lToDeleteAvatar = $lOldAvatar;
Model_Avatars::delete($lVal);
$lUserData['avatar_id'] = '';
break;
}
}
$lResult = Auth::update_user($lUserData, $lUserName);
if (!empty($lNewAvatar)) {
FileHandler::moveFiles($lNewAvatar, FileHandler::tempFolder(), FileHandler::AVATAR_FOLDER);
}
if (!empty($lToDeleteAvatar)) {
FileHandler::deleteFiles([FileHandler::AVATAR_FOLDER . $lToDeleteAvatar['file_name']]);
}
DB::commit_transaction();
} catch (Exception $e) {
DB::rollback_transaction();
die(json_encode(['status' => 'error', 'message' => 'Error ' . $e], JSON_UNESCAPED_UNICODE));
}
if ($lResult) {
die(json_encode(['status' => 'ok'], JSON_UNESCAPED_UNICODE));
}
die(json_encode(['status' => 'error', 'message' => 'Fields not were updated'], JSON_UNESCAPED_UNICODE));
}