public function saveTrack(Request $request) { $this->validate($request, ['mp3' => 'max:7000']); $userID = Auth::user()['id']; if (RequestF::hasFile('mp3')) { $file = RequestF::file('mp3'); if ($file->isValid()) { $target_dir = "audio/" . $userID; //if target_dir doesn't exist, create it if (!is_dir($target_dir)) { Storage::makeDirectory($target_dir); } if ($file->move(storage_path() . "/app/" . $target_dir, $file->getClientOriginalName())) { //if($track == null) { $track = new Track(); //fill in fields $track->band_id = $userID; $track->song_name = RequestF::input('track'); $track->authors = RequestF::input('artist'); $track->file_path = storage_path() . "/app/" . $target_dir . "/" . $file->getClientOriginalName(); $track->save(); return new RedirectResponse(url('/tracks')); //} } } } return new RedirectResponse(url('/tracks')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $track = Track::all(); $track = new Track(); $artist = Artist::all(); $artist = new Artist(); $id_artist = Input::get('id_artist'); $track_name = Input::get('name'); $track->id_artist = $id_artist; $track->name = $track_name; $archivo = array('file' => Input::file('file')); //$extension = Input::file('file')->getClientOriginalExtension(); $file_name = Input::file('file')->getClientOriginalName(); // $new_name = $this->replace_white_spaces($file_name); //ejecuta el metodo para caracteres especiales $dir_file = "/home/jona/Proyecto_Beto/CyberRockola/CyberRockola/uploads/rockola_music/"; //dirección fisica de las canciones Input::file('file')->move($dir_file, $new_name); //mueve con el nombre nuevo $track->dir_track = $dir_file . $new_name; //dirección exacta con el nombre de la cancion y extension $track->save(); return redirect('tracks'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // Check to see if anime exists, if not then create new anime record $series = Anime::where('url', $request->input('anime_url'))->first(); if ($series === null) { $series = new Anime(); $series->name = $request->input('anime_name'); $series->user_id = Auth::user()->id; $series->image = $request->input('anime_image'); $series->synopsis = $request->input('anime_synopsis'); $series->url = $request->input('anime_url'); $series->save(); } $mp3 = $request->file('track'); $track = new Track(); $track->name = $request->input('name'); $track->user_id = Auth::user()->id; $track->anime_id = $series->id; $track->track = $mp3->getClientOriginalExtension(); $track->save(); if (!$request->hasFile('track')) { return "no file uploaded"; } //Use some method to generate your filename here. Here we are just using the ID of the image $filename = $track->id . "." . $track->track; //Push file to S3 Storage::disk('s3')->put($filename, file_get_contents($mp3)); return redirect()->route('home')->with('status', 'Track Added!'); }
public function postNew(Request $request) { $this->validate($request, ['title' => 'required', 'audio-file' => 'required']); $track = new Track(); $track->title = $request->title; $track->desc = $request->desc; $track->save(); $track->private = $request->lock ? true : false; $track->private_key = substr(md5($track->created_at), 0, 6); $track->user_id = $request->user()->id; $track->save(); Input::file('audio-file')->move('audio/', $track->id . '.mp3'); if ($track->private) { return redirect('track/view/' . $track->id . '/' . $track->private_key); } else { return redirect('track/view/' . $track->id); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $track = Track::all(); $track = new Track(); $artist = Artist::all(); $artist = new Artist(); $id_artist = Input::get('id_artist'); $track_name = Input::get('name'); $track->id_artist = $id_artist; $track->name = $track_name; $archivo = array('file' => Input::file('file')); $extension = Input::file('file')->getClientOriginalExtension(); $file_name = Input::file('file')->getClientOriginalName(); $new_name = $this->replace_white_spaces($file_name); $dir_file = "uploads/rockola_music/"; Input::file('file')->move($dir_file, $new_name); $track->dir_track = $dir_file . $new_name; $track->save(); return redirect('tracks'); }
/** * Checks to see if there are any dowloads let on a specific track. If not it send said track to a Job to be deleted. * * @var \Request, \Track * @return json */ public function checkDownload(Request $request, Track $track) { $app = app(); $message_return = $app->make('stdClass'); if ($track->max_downloads > $track->current_downloads) { $track->current_downloads += 1; $track->save(); $message_return->message = "success"; return response()->json(['message_return' => $message_return], 200); } else { $message_return->message = "failure"; $job = new DeleteTracks($track); $this->dispatch($job); return response()->json(['message_return' => $message_return], 200); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\AddSongRequest $request) { /* cases: add track walang artist, walang album / may artist, walang album add lang talaga */ //Start of Inserting a music //Start here. //dd($request->get('name')); //else{ //dd(\Auth::user()->id); $track = new Track(array('name' => $request->get('name'), 'creator_id' => \Auth::user()->id)); $track->save(); flash()->overlay('Track uploaded.', 'Success!'); //https://www.codetutorial.io/laravel-5-file-upload-storage-download/ $fileName = $track->id . '.' . $request->file('image')->getClientOriginalExtension(); $path = base_path() . '/public/tracks/' . $fileName; $request->file('image')->move(base_path() . '/public/tracks/', $fileName); //dd($path); $path = '/public/tracks/' . explode("/", $path)[sizeof(explode("/", $path)) - 1]; //get value at last element //dd($path); DB::table('tracks')->where('id', $track->id)->update(['path' => $path]); //song is now uploaded and has filePath //dd($request->get('artist_name')); //getting an artist $artist = DB::table('artists')->where('name', $request->get('artist_name'))->first(); //dd($artist); //} if ($artist) { //artist exists $artistHasSong = new ArtistHasSong(array('artist_id' => $artist->id, 'track_id' => $track->id)); $artistHasSong->save(); $album = DB::table('albums')->join('albums_has_artist', 'albums_has_artist.album_id', '=', 'albums.id')->select('albums_has_artist.*')->where('albums_has_artist.artist_id', '=', $artist->id)->where('albums.name', '=', $request->get('album_name'))->first(); /* select * from albums_has_artist a inner join albums b on a.albumId = b.albumId where a.artist_id = $artist->id and b.name= $request->get('album_name') */ //dd($album); if ($album) { //track and album exist and artist exist $albumHasSong = new AlbumHasSong(array('album_id' => $album->id, 'track_id' => $track->id)); $albumHasSong->save(); return redirect()->back(); // return view('track.create', // ['message'=>'Track Created']); } else { //album does not exist but artist and track exists // return redirect('/album/create') // ->with(['track_id' => $track->id, 'artist_name' => NULL, // 'artist_id' => $artist->id, 'album_name' => $request->get('album_name')]); return view('album.create', ['track_id' => $track->id, 'artist_name' => NULL, 'artist_id' => $artist->id, 'album_name' => $request->get('album_name')]); } } else { //track exist now(); artist does not exist //to do on artist store artists has song: //to do on album store album has artist and album has song //dd($request->get('artist_name')); if ($request->get('artist_name') != NULL) { // return redirect('/artist/create') // ->with(['artist_name' => $request->get('artist_name'), 'track_id' => $track->id, // 'track_name' => $track->name, 'album_name' => $request->get('album_name')]); return view('artist.create', ['artist_name' => $request->get('artist_name'), 'track_id' => $track->id, 'track_name' => $track->name, 'album_name' => $request->get('album_name')]); } else { // return redirect('/album/create') // ->with(['artist_name' => $request->get('artist_name'), 'artist_id' => NULL, // 'track_id' => $track->id, 'album_name' => $request->get('album_name')]); return view('album.create', ['artist_name' => $request->get('artist_name'), 'artist_id' => NULL, 'track_id' => $track->id, 'album_name' => $request->get('album_name')]); } } }