Changeset e78295c for app/Http/Controllers/Dashboard/FilesController.php
- Timestamp:
- 10/31/21 21:28:46 (3 years ago)
- Branches:
- master
- Children:
- 4521f25
- Parents:
- a55bb54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/FilesController.php
ra55bb54 re78295c 54 54 if ($request->has('file_item')) { 55 55 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 57 64 $file->storeAs($location . DIRECTORY_SEPARATOR, $fileName); 58 65 $newFile = new File(); … … 63 70 $newFile->save(); 64 71 } 65 Notification::send($users, new NewFileCreated("New files added"));66 72 67 73 Alert::flash("New files added successfully"); … … 81 87 return Storage::download($file->location); 82 88 } 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 }107 89 }
Note:
See TracChangeset
for help on using the changeset viewer.