本文整理汇总了PHP中Func::getImgPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Func::getImgPath方法的具体用法?PHP Func::getImgPath怎么用?PHP Func::getImgPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::getImgPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateProfilePicture
public function updateProfilePicture()
{
$user = $this->model->where('id', '=', $_POST['user_id'])->first();
$now = \Carbon\Carbon::instance($user->created_at);
$types = array('_o.', '_s.', '_m.', '_l.');
$sizes = array(100, 300, 600);
$target_path = base_path() . '/public/imgs/';
$file = \Input::file('image');
$hashSeed = "user" . $user->id . $file->getClientOriginalName();
while (1) {
$file_name = \Func::getHashedValue($hashSeed);
if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
break;
}
$hashSeed .= rand();
}
$target_path .= \Func::getImgPath($file_name) . '/';
if (!\File::exists($target_path)) {
\File::makeDirectory($target_path, 0775, true);
}
$file_ext = $file->getClientOriginalExtension();
$original = $file_name . array_shift($types) . $file_ext;
$file->move($target_path, $original);
// Move the original one first
foreach ($types as $key => $type) {
$new_name = $file_name . $type . $file_ext;
\File::copy($target_path . $original, $target_path . $new_name);
\Image::make($target_path . $new_name)->resize($sizes[$key], null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save($target_path . $new_name);
}
\File::delete($target_path . $original);
$user->profile_img_path = $file_name . "." . $file_ext;
$user->save();
$this->common_func->storeActivityLogWithUser('update_user_profile_picture', $user->id, 'user', $_POST['user_id']);
return $user;
}
示例2: storeAPI
public function storeAPI()
{
\DB::beginTransaction();
try {
// post save
$post = $this->model->create(array('user_id' => $_POST['user_id'], 'content' => $_POST['captions']));
if (!$post) {
\DB::rollback();
return;
}
$post_group = $this->post_group->where('post_groups.user_id', '=', $_POST['user_id'])->where('post_groups.name', '=', "Uncategorized")->first();
$post->postGroups()->attach($post_group->id);
$types = array('_o.', '_s.', '_m.', '_l.');
$sizes = array(100, 300, 600);
$target_path = base_path() . '/public/imgs/';
$file = \Input::file('image');
$hashSeed = "post" . $post->id . $file->getClientOriginalName();
while (1) {
$file_name = \Func::getHashedValue($hashSeed);
if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
break;
}
$hashSeed .= rand();
}
$target_path .= \Func::getImgPath($file_name) . '/';
if (!\File::exists($target_path)) {
\File::makeDirectory($target_path, 0775, true);
}
$file_ext = $file->getClientOriginalExtension();
$original = $file_name . array_shift($types) . $file_ext;
$file->move($target_path, $original);
// Move the original one first
foreach ($types as $key => $type) {
$new_name = $file_name . $type . $file_ext;
\File::copy($target_path . $original, $target_path . $new_name);
\Image::make($target_path . $new_name)->resize($sizes[$key], null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save($target_path . $new_name);
}
\File::delete($target_path . $original);
$photo = $this->photo->create(array('post_id' => $post->id, 'sequence' => 1, 'img_path' => $file_name . '.' . $file_ext));
if (!$photo) {
\DB::rollback();
return;
}
// hash tag save
$temp = $_POST['captions'];
preg_match_all('/#(\\w+)/', $temp, $matches);
$hashtags = $matches[1];
foreach ($hashtags as $hashtag) {
$tag = $this->tag->firstOrCreate(['name' => $hashtag]);
$post->Tags()->attach($tag->id);
}
$this->common_func->storeActivityLogWithUser('store_post', $post->id, 'post', $_POST['user_id']);
} catch (ValidationException $e) {
\DB::rollback();
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
\DB::commit();
return $post;
}