Ignore:
Timestamp:
10/31/21 21:28:46 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
master
Children:
4521f25
Parents:
a55bb54
Message:

added version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/FilesController.php

    ra55bb54 re78295c  
    5454        if ($request->has('file_item')) {
    5555            foreach ($request->file_item as $file) {
    56                 $fileName = $folder->name . '-' . uniqid() . '.' . $file->getClientOriginalExtension();
     56                $fileName = $file->getClientOriginalName();
     57
     58                if(File::where(['folder_id' => $folder->id, 'name' => $fileName])->count() > 0) {
     59                    Alert::flash("The uploaded file already exists", "error");
     60
     61                    return redirect()->back();
     62                }
     63
    5764                $file->storeAs($location . DIRECTORY_SEPARATOR, $fileName);
    5865                $newFile = new File();
     
    6370                $newFile->save();
    6471            }
    65             Notification::send($users, new NewFileCreated("New files added"));
    6672
    6773            Alert::flash("New files added successfully");
     
    8187        return Storage::download($file->location);
    8288    }
    83 
    84     public function renameFile(FileNameRequest $request, $id)
    85     {
    86         $file = File::find($id);
    87         $fileExtension = explode('.', $file->name)[1];
    88 
    89         $file->name = $request->name . '.' . $fileExtension;
    90         $newLocation = 'Departments' . DIRECTORY_SEPARATOR . explode(DIRECTORY_SEPARATOR, $file->location)[1] . DIRECTORY_SEPARATOR . explode(DIRECTORY_SEPARATOR, $file->location)[2] . DIRECTORY_SEPARATOR . $file->name;
    91 
    92         if(Storage::disk('uploads')->has($newLocation)) {
    93             Alert::flash("A file with the same name already exists", "error");
    94             return redirect()->back();
    95         }
    96         else {
    97             Storage::disk('uploads')->move($file->location, $newLocation);
    98 
    99             $file->location = $newLocation;
    100             $file->updated_at = Carbon::now();
    101             $file->save();
    102 
    103             Alert::flash($file->name . " updated successfully");
    104             return redirect()->back();
    105         }
    106     }
    10789}
Note: See TracChangeset for help on using the changeset viewer.