예제 #1
0
 public function uploadPost(Request $request, Folder $folder)
 {
     $this->authorize('all', $folder);
     $file = $request->file('file');
     if (!$file) {
         fmsgs(['title' => 'No File Detected', 'type' => 'error', 'text' => 'Please provide the file you want to upload!']);
         return redirect()->back();
     }
     $extension = $file->getClientOriginalExtension();
     if (!$file->isValid()) {
         fmsgs(['title' => 'File is not Valid', 'type' => 'error', 'text' => $file->getErrorMessage()]);
         return redirect()->back();
     }
     $filename = $file->getFilename() . '.' . $extension;
     $name = $file->getClientOriginalName();
     $storage = Storage::disk('local')->put($filename, file_get_contents($file->getRealPath()));
     $file = FileModel::create(['name' => $name, 'filename' => $filename, 'folder_id' => $folder->id]);
     if (explode('/', fileInfo($file)['type'])[0] === 'image' && explode('/', mimeTypeFromString($extension))[0] === 'image') {
         $this->createOptimizedImage($filename);
     }
     if ($this->user->auto_share) {
         $this->_share($file, 1, true, false);
     }
     fmsgs(['title' => 'File Uploaded', 'type' => 'success', 'text' => 'The file uploaded successfully']);
     return redirect('/files/' . $folder->id);
 }
예제 #2
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     User::created(function (User $user) {
         Folder::create(['name' => '/', 'user_id' => $user->id]);
         Activity::create(['type' => 'user_created', 'user_id' => $user->id]);
     });
     Folder::deleting(function (Folder $folder) {
         foreach ($folder->folders as $_folder) {
             $_folder->_delete();
         }
         foreach ($folder->files as $file) {
             $file->delete();
         }
     });
     File::deleting(function (File $file) {
         $file = updateFile($file, fileInfo($file));
         $filenames = [];
         if ($file->type == 'image') {
             $altImages = ['opt', 'xs'];
             foreach ($altImages as $suffix) {
                 $name = explode('.', $file->filename)[0];
                 $extension = explode('.', $file->filename)[1];
                 array_push($filenames, "{$name}.{$suffix}.{$extension}");
             }
         }
         Storage::delete($file->filename);
         if (!empty($filenames)) {
             foreach ($filenames as $filename) {
                 Storage::delete($filename);
             }
         }
     });
 }
예제 #3
0
 public function index()
 {
     $activities = Activity::orderBy('updated_at', 'desc')->get();
     $activities = $activities->unique(function ($item) {
         return $item->user_id . $item->type . $item->item_id;
     });
     $users = User::all();
     $userIds = array_map(function ($user) {
         return $user['id'];
     }, $users->toArray());
     foreach ($activities as $index => $activity) {
         if (!in_array($activity->user_id, $userIds)) {
             unset($activities[$index]);
         }
         if ($activity->item_id) {
             $file = FileModel::find($activity->item_id);
             if (!$file || !$file->shared) {
                 unset($activities[$index]);
             }
         }
     }
     return view('home', ['activities' => $activities]);
 }
예제 #4
0
파일: helpers.php 프로젝트: dwijpr/share
 function ppSrc(User $user, $suffix = false)
 {
     $path = 'img/default-' . ($user->gender ? 'male' : 'female') . '.png';
     if ($user->profile_picture_id) {
         if (FileModel::find($user->profile_picture_id)) {
             $path = '/file/' . $user->profile_picture_id;
             if ($suffix) {
                 $path .= "/{$suffix}";
             }
         }
     }
     return url($path);
 }