Пример #1
0
 public function uploadFiles(Request $request)
 {
     $destinationPath = "media";
     $files = $request->file("myFiles");
     $uploadCount = 0;
     $lastFile = MediaStorage::orderBy('id', 'Desc')->take(1)->get()->toArray();
     $fileCount = count($files);
     foreach ($files as $file) {
         $uploadCount++;
         if (count($lastFile) === 0) {
             $fileName = strval(count($lastFile) + 1) . "_" . $file->getClientOriginalName();
             $uploadSuccess = $file->move($destinationPath, $fileName);
             MediaStorage::create(["filename" => $file->getClientOriginalName(), "filesize" => $file->getSize(), "filelocation" => "/" . $destinationPath . "/" . $fileName]);
             $lastFile = MediaStorage::orderBy('id', 'Desc')->take(1)->get()->toArray();
         } else {
             $fileName = ++$lastFile[0]['id'] . "_" . $file->getClientOriginalName();
             $uploadSuccess = $file->move($destinationPath, $fileName);
             MediaStorage::create(["filename" => $file->getClientOriginalName(), "filesize" => $file->getSize(), "filelocation" => "/" . $destinationPath . "/" . $fileName]);
         }
     }
     return view("successful-upload", compact('uploadCount'));
 }
Пример #2
0
 public function showDownloads()
 {
     $data = MediaStorage::where('isDeleted', '=', 0)->orderBy('id', 'desc')->get()->toArray();
     return view('downloads', compact('data'));
 }