我遇到了上传mp3文件
的问题每当我发送表格时,我都会收到一份"文件""没找到。
那是我从POST数据中得到的:
这是控制器:
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();
}
以下是观点:
<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>
我看到这是一个经常出现的问题,但没有找到任何解决方案:( 我已经尝试过mimes:audio / mpeg但没什么......
答案 0 :(得分:0)
您遇到该问题的原因有4/5。
1-您正在上传一个大文件,并且没有更改php.ini文件以允许文件大小超过某个值。更改这些变量的值。
post_max_size = 2G
or 500M
upload_max_filesize=500M
2-您已经更改了php.ini,但没有重新启动服务器。
3-您弄乱了路线。
4-您的HTML表单不正确。您可能会丢失:
enctype="multipart/form-data"
Also,
<input type="file" name="pic" accept="audio/*">
5-您没有更改
file_uploads = On
``` in php.ini file