在laravel中动态创建上传文件夹

时间:2017-01-26 02:08:50

标签: laravel-5

我想知道如何动态创建上传文件夹。 我有歌曲控制器。这是我的商店方法。

public function store(Request $request)
    {
        //
        $this->validate($request, [
            'title' => 'required',
            'lyrics' => 'required',
            'youtube_id' => 'required',
            'album_id' =>   'required|integer',
            'category_id' => 'required|integer'

        ]);
        $song = new Song;
        $song->title = $request->title;
        $song->lyrics = $request->lyrics;
        $song->youtube_id = $request->youtube_id;
        $song->album_id = $request->album_id;
        $song->category_id = $request->category_id;

        if($request->hasFile('mp3')){
            $mp3 = $request->file('mp3');
            $trackname = $mp3->getClientOriginalName();
            $path = public_path('/uploads/songs');
            $mp3->move($path, $trackname);
            $song->mp3 = $trackname;
        }
        $song->save();
        $song->artists()->sync($request->artists, false);
        return redirect()->route('song.index')->with('success', 'New song successfully upploaded');
    }

我想创建一个用艺术家名称重命名的文件夹。对于属于正在上传的歌曲的每位艺术家。

1 个答案:

答案 0 :(得分:0)

=