Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  StoreMediaRequest  $request
  * @return Response
  */
 public function store(StoreMediaRequest $request)
 {
     if ($request->ajax()) {
         $response = ['error' => 1, 'path' => ''];
         if ($request->hasFile('file')) {
             $file = $request->file('file');
             $path = '/uploads/posts/' . date('Y-m-d');
             $destination = storage_path('app' . $path);
             $hashed = sha1(Str::slug($file->getClientOriginalName() . time())) . '.' . $file->getClientOriginalExtension();
             if (!\File::exists($destination)) {
                 \File::makeDirectory($destination);
             }
             if ($file->move($destination, $hashed)) {
                 $medium = $this->medium->create(['path' => $path . '/' . $hashed]);
                 if ($medium) {
                     $response['error'] = 0;
                     $response['path'] = $path . '/' . $hashed;
                     return response($response, 200);
                 }
                 // TODO: ln -s /path/to/public_html/storage/app/uploads /path/to/public_html/public/uploads
             }
         }
     }
     return response('error', 400);
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  StoreMediaRequest  $request
  * @return Response
  */
 public function store(StoreMediaRequest $request)
 {
     if ($request->ajax()) {
         $response = ['error' => 1, 'path' => ''];
         if ($request->hasFile('file')) {
             $file = $request->file('file');
             $folder = '/public/uploads/' . $request->folder;
             if (!\Storage::exists($folder)) {
                 \Storage::makeDirectory($folder);
             }
             $path = $folder . '/' . date('Y-m-d');
             $hashed = sha1(Str::slug($file->getClientOriginalName() . time())) . '.' . $file->getClientOriginalExtension();
             if (!\Storage::exists($path)) {
                 \Storage::makeDirectory($path);
             }
             if ($file->move(storage_path('app') . $path, $hashed)) {
                 $path = str_replace('/public', '', $path);
                 $medium = $this->medium->create(['path' => $path . '/' . $hashed]);
                 if ($medium) {
                     $response['error'] = 0;
                     $response['path'] = $path . '/' . $hashed;
                     return response($response, 200);
                 }
                 // TODO: ln -s storage/app/public/uploads /path/to/public_html/public
             }
         }
     }
     return response('error', 400);
 }