Have you tried the mimtype validator? Something like:
'upload' => 'mimetypes:jrxml'
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is there a simple way to do this? I need to ensure that the file uploaded is .jrxml.
I guess that the mime type will be too generic.
Mick
Have you tried the mimtype validator? Something like:
'upload' => 'mimetypes:jrxml'
That fails and says that the file should be of type jrxml.
I don't think any of the Laravel stuff will work, I just need to check the extension somehow, in the rules.
Mick
@Screenbeetle @phpMick It should be mimes:jrxml instead of mimetypes:jrxml. This will check the extension.
"mimetypes" works too, but the full type must be specified, e.g. mimes:image/jpeg
I have:
$rules['template_file'] = 'required|file|mimes:jrxml';
This gives: file should be of type jrxml.
and
$rules['template_file'] = 'required|file|mimetypes:application/octet-stream';
gives the file must be of type application/octet-stream
"I don't think any of the Laravel stuff will work, I just need to check the extension somehow, in the rules."
Hi again
I can only suggest something like grabbing the file extension as a string (using Jquery or php) and setting that into a field first. You can then pass that field in the request to the validator to check.
It's not elegant but should work.
Yeah I can easily add the extension to the Ajax request.
How then do I then make a rule for = "jrxml".
Yes I know it's never going to be elegant I just want to stop my users uploading random files :-)
Sorry - do you mean how to match 'jrxml' as a string?
I don't recall ever needing to do that now that you mention it. Is there a validator rule to match an input value to a specific string? You can probably do it with regex .. something like
'upload-extension' => ["required" , "regex:(jrxml)"]
but that seems a bit OTT .. hmm, (brain not really in gear today thanks to the election)
$rules['template_file'] = 'required|file|mimes:jrxml';
@phpMick This should work just fine for checking file extensions? Did you remember to set the enctype="multipart/form-data" attribute for your <form> element? This is required when uploading files.
@Nash yes, but as stated above, this is not working.
<form class="form-horizontal" role="form" enctype="multipart/form-data" files="true">
And you are using method="POST" and <input type="file" name="template_file">?
Sorry if the question seems silly. I'm just curious why the mimes rule won't work since I just recently used it without problem in one of my own projects.
Hi @Nash
I also have several working examples using mimes - catalogue' => 'required|mimes:pdf', etc. Now I could be totally wrong but I think the issue may be that it only recognizes certain extensions based on the contents of the file itself.
Below is what the laravel docs links to as the official list and jrxml doesn't seem to appear:
https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
It's because it's not a common minetype.
No, I'm not posting, I'm using Ajax.
Please or to participate in this conversation.