简体   繁体   中英

Laravel - Upload mp3 file failed

I met a problem with upload of an mp3 file

Everytime I send the form I got a "File "" not found.

and that's what i got from my POST DATA :

IMAGE OF POST DATA

Here it's the controller :

public function Display()
{
    return view('pages.new');
}


public function Post(Request $request)
{
    $rules = [
        'name' => ['required'],
        'sources' => ['required'],
        'cover' => ['required'],
        'resume-podcast' => ['required'],
    ];

    $validator = Validator::make($request->all(), $rules);

    $pathimg = $request->file('cover')->store('/audio/cover');
    $pathsources = $request->file('sources')->store('/audio/sources');

    $podcasts = Audio::create(
            [
            'name' => request('name'),
            'user_id' => auth()->id(),
            'sources' => $pathsources,
            'cover' => $pathimg,
            'description' => request('resume'),
        ]);



    return($pathsources);
    flash("Yes !")->success();
}

Here it's the view :

 <form action="/new" method="POST" enctype="multipart/form-data">
        {{ csrf_field() }}
        <div class="form-group" >
            <label for="exampleInputPassword1">Nom podcast</label>
            @if($errors->has('name'))
                <p class="bg-warning"> {{ $errors->first('name') }}</p>
            @endif
            <input class="form-control" name="name" id="name" type="text" aria-describedby="emailHelp" placeholder="Nom du podcast">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Description du podcast</label>
            @if($errors->has('resume-podcast'))
                <p class="bg-warning"> {{ $errors->first('resume-podcast') }}</p>
            @endif
            <input class="form-control" name="resume-podcast" id="resume-podcast" type="text" aria-describedby="emailHelp" placeholder="Description rapide">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Source (url)</label>
            @if($errors->has('sources'))
                <p class="bg-warning"> {{ $errors->first('sources') }}</p>
            @endif
            <input class="form-control" id="sources" name="sources" type="file">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Cover (url)</label>
            @if($errors->has('cover'))
                <p class="bg-warning"> {{ $errors->first('cover') }}</p>
            @endif
            <input class="form-control" id="cover" name="cover" type="file>
        </div>
        <input type="submit" class="btn btn-primary btn-block" value="Ajouter podcast">
    </form>
                </div>
            </div>
        </div>

I saw it was a recurrent problem but didn't find any solution :( I already try with mimes:audio/mpeg but nothing...

There are 4/5 reasons why you faced that issue.

1 - You're uploading a large file and didn't change the php.ini file to allow file sized more than a certain value. change the value of these variables.

post_max_size = 2G
or 500M
upload_max_filesize=500M

2 - You've changed the php.ini but didn't restart the server.

3 - You've messed up the route.

4 - Your HTML form isn't correct. You might be missing:

enctype="multipart/form-data"
Also,
<input type="file" name="pic" accept="audio/*">

5 - You didn't change

file_uploads = On
``` in php.ini file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM