-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addField type browse file restriction #498
Comments
You can of course write your own "upload" field type (take a look at custom field types in the doc) Or you can hook into the store (new) and update functions inside your WhateverCrudController.php to validate the uploaded files and deny them if they don't comply with your requirements, something along the lines... public function store(StoreRequest $request)
{
if (!$this->validate_upload()) { /* Custom function that validates uploaded files mimes */
return \Redirect::back()->withErrors(\Validator::make(\Input::all(), [])->getMessageBag()->add('tutorias', 'Incorrect file type on create!');)->withInput();
}
$redirect_location = parent::storeCrud();
return $redirect_location;
}
public function update(UpdateRequest $request)
{
if (!$this->validate_upload()) { /* Custom function that validates uploaded files mimes */
return \Redirect::back()->withErrors(\Validator::make(\Input::all(), [])->getMessageBag()->add('tutorias', 'Incorrect file type on update!');)->withInput(); }
}
$redirect_location = parent::updateCrud();
return $redirect_location;
} |
I knew my question was rather noobish but i was frustrated last night about this. Thank you for your response. I wish you a very good day. |
Although i still think mime filter should be added as an extra option. like:
|
No noobish questions, just a desire to learn, that's great. If you want that, you need to create a custom field type; and even doing so, you'll still have to create a validation, as you can't trust every browser out there to follow your specifications. |
Its not a complete solution but in the request validation u could do something like this in the rules function: |
Hey
I'm new to Backpack and I'm having a great time not reinventing the wheel :). I have this code in one of my CrudControllers:
My question is how can i restrict file types allowed to upload? Lets say i want user to be able to upload only 'jpeg' or 'mp3'. How can i achieve that?
I've looked up 'vendor/backpack/crud/src/resources/views/fields/browse.blade.php' to set the restriction there but the input use is of 'text' type not 'file' type.
Anyways a big thanks to contributers of this awesome package. peace.
The text was updated successfully, but these errors were encountered: