Example #1
2
 public static function upload(UploadedFile $file, $user, $contest = null)
 {
     $entry = new static();
     DB::transaction(function () use($entry, $file, $user, $contest) {
         $entry->save();
         // get id
         $entry->user()->associate($user);
         $entry->contest()->associate($contest);
         $entry->filesize = $file->getClientSize();
         $entry->original_filename = $file->getClientOriginalName();
         $entry->storeFile($file->getRealPath(), $file->getClientOriginalExtension());
         $entry->save();
     });
     return $entry;
 }
 /**
  * Store the uploaded file on the disk with a given name.
  *
  * @param  string  $path
  * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
  * @param  string  $name
  * @param  string  $visibility
  * @return string|false
  */
 public function putFileAs($path, $file, $name, $visibility = null)
 {
     $stream = fopen($file->getRealPath(), 'r+');
     $result = $this->put($path = trim($path . '/' . $name, '/'), $stream, $visibility);
     if (is_resource($stream)) {
         fclose($stream);
     }
     return $result ? $path : false;
 }
Example #3
0
 /**
  * Move the avatar file into storage.
  *
  * @param UploadedFile $file
  * @param User         $user
  * @return static
  *
  * @author Cali
  */
 public static function move(UploadedFile $file, User $user)
 {
     $path = 'avatars/' . $user->id . '/' . $file->hashName();
     Storage::put($path, file_get_contents($file->getRealPath()));
     $avatar = new static(['type' => 0, 'src' => $path]);
     $user->avatars()->save($avatar);
     return $avatar;
 }
Example #4
0
 /**
  * @param UploadedFile $file
  *
  * @return bool
  */
 protected function isImageUploadedFile(UploadedFile $file)
 {
     $size = getimagesize($file->getRealPath());
     return (bool) $size;
 }
Example #5
0
 /**
  * 生成文件名
  *
  * @param  \Illuminate\Http\UploadedFile $file
  * @return string
  */
 protected function makeFilename(UploadedFile $file)
 {
     return md5_file($file->getRealPath()) . "." . $file->getClientOriginalExtension();
 }