@jaheller The file is larger than what is allowed by your PHP configuration so PHP rejects it. It never makes it to your Laravel application code. That's why there is no file. Try a much smaller file and you'll see that the MIME check works just fine.
Jan 17, 2016
15
Level 13
laravel5.1 size validator doesn't work on fileupload
In my controller I want to set a maximum filesize and some allowed mime types a user can upload. I tried the max and size rule, none of them seems to work, I can set them to "1" and I can still upload files. The MIME types seems to be ignored. For example I can still try to upload the git setup (29MB and a .exe file)!
controller:
public function postTicket(Request $request)
{
$validator = Validator::make($request->all(), [
'departments' => 'exists:departments,id',
'attachment' =>'min:1|max:1000|mimes:txt,text,log',
]);
if ($validator->fails())
return back()->withErrors($validator)->withInput();
if ($request->hasFile('attachment'))
{
if ($request->file('attachment')->isValid())
{
$request->file('attachment')->move('../storage/app/uploads', 'lala.txt');
dd("uploaded");
}
dd("upload failed");
}
dd("no file");
}
Where's my fault I mean the validator rule doesn't check the git setup for example, with it's 29MB it should fail the size check and the MIME type exe isn't allowed too. It passes the check and all I see is:
Warning: POST Content-Length of 30617046 bytes exceeds the limit of 4194304 bytes in Unknown on line 0
"no file"
Level 42
@jaheller Positioning is just a matter of CSS. The following re-arranges the elements and prevents submission if rejected files are present.
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dropzone Test</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.css" rel="stylesheet">
<style>
.dropzone {
border: none;
}
.dropzone-container {
border: 2px dashed #0087F7;
border-radius: 5px;
}
.dropzone-previews {
background: white;
padding: 10px 10px;
margin: 1em 0;
}
.dropzone .dz-message {
color: rgb(100, 108, 127);
font-weight: 400;
font-size: 20px;
text-align: center;
margin: 1em 0;
}
</style>
</head>
<body>
<form action="{{ asset('dropzone') }}" method="post" class="dropzone" id="uploads">
{{ csrf_field() }}
<input type="text" name="testinput" id="testinput" value="Hi there">
<div class="dropzone-previews"></div>
<div class="dropzone-container">
<div class="dz-message">Drop files here</div>
</div>
<button type="submit" id="submit-form" style="margin-top: 2em">Submit</button>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>
<script>
Dropzone.options.uploads = {
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
addRemoveLinks: true,
previewsContainer: ".dropzone-previews",
clickable: ".dz-message",
maxFilesize: 1,
acceptedFiles: "text/plain",
init: function() {
var myDropzone = this;
this.element.querySelector("#submit-form").addEventListener("click", function(e) {
if (myDropzone.getRejectedFiles().length>0) {
e.preventDefault();
e.stopPropagation();
return;
}
if (myDropzone.getQueuedFiles().length>0) {
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
}
});
}
};
</script>
</body>
</html>
Please or to participate in this conversation.