Hi im currently coding a gallery in laravel 5 where you can upload images and videos in separted categorys and i got a pretty strange problem with the valdidation method.
The image upload itself works fine and does exactly what it should. But if i try to upload videos (mp4,webm) my Validation always fails with the error, that the file field is required. But if i try the same with a wrong mime type file all works like intended and i the validation method says its the wrong mime type.
The view looks the following:
@extends('templates.base')
@section('content')
@parent
{!! Form::open(['url' => '/gallery/upload/' .$gallery->id, 'files' => true]) !!}
<div>
{!! $error !!}
</div>
<table>
<tr>
<td>
Title:
</td>
<td>
{!! Form::text('title',old('title'),['class' => 'form_text', 'min' => '3', 'max' => '255']) !!}
</td>
</tr>
<tr>
<td>
Description:
</td>
<td>
{!! Form::textarea('description') !!}
</td>
</tr>
<tr>
<td>
File:
</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
{!! Form::file('file') !!}
</td>
</tr>
<tr>
<td>
External:
</td>
<td>
<select name="external">
<option value="0" default>No</option>
<option value="1">Yes</option>}
</select>
</td>
</tr>
<tr>
<td>{!! Form::submit(trans('strings.create'),['class' => 'form_submit news']) !!}</td>
</tr>
</table>
{!! Form::close() !!}
@stop
The controller looks something like this:
if (config('gallery.allowUploads')) {
if (config('gallery.allowUserUploads')) {
$gallery = Gallery::find($request->route('id'));
if (is_null($request->route('id')) || count($gallery) <= 0) {
return redirect()->back();
}
if ($request->isMethod('post')) {
if ($gallery->type == 'i') {
$Validator = Validator::make($request->all(), [
'title' => 'required|min:3|max:255',
'description' => 'max:10000',
'file' => 'required|mimes:jpg,jpeg,bmp,png,gif',
'external' => 'required|in:0,1',
]);
} elseif ($gallery->type == 'v') {
$Validator = Validator::make($request->all(), [
'title' => 'required|min:3|max:255',
'description' => 'max:10000',
'file' => 'required|mimes:mp4,webm',
'external' => 'required|in:0,1',
]);
} else {
$Validator = Validator::make($request->all(), [
'title' => 'required|min:3|max:255',
'description' => 'max:10000',
'file' => 'required|mimes:zip,rar,7z',
'external' => 'required|in:0,1',
]);
}
$error = "";
if ($Validator->fails()) {
foreach ($Validator->messages()->All() as $m) {
$error .= $m . "</br>";
}
return view('gallery/items/create', ['gallery' => $gallery, 'error' => $error);
}
When im uploading a webm
dd($request->file('file'),$gallery->type);
returns
UploadedFile {#29 ▼
-test: false
-originalName: "big-buck-bunny_trailer.webm"
-mimeType: "application/octet-stream"
-size: 0
-error: 1
}
"v"
But the Validation Method still says it fails because the file field is required.
I just feel like i'm overlooking something. Thanks for your help.
edit:
i just found that when im uploading an image file i get
UploadedFile {#29 ▼
-test: false
-originalName: "a8b5KQQ_460s_v1.jpg"
-mimeType: "image/jpeg"
-size: 53991
-error: 0
}
"v"
that error is 0 and on the webm file its 1 but i'm not sure what it means.