-
Notifications
You must be signed in to change notification settings - Fork 251
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
file size per file type? #304
Comments
This feature isn't implemented and it's quite specific to implement. The good news is that you can solve is by yourself.
namespace Custom;
use RFM\Repository\Local\Storage as LocalStorage;
class Storage extends LocalStorage
{
/**
* Initiate uploader instance and handle uploads.
*
* @inheritdoc
*/
public function initUploader($model)
{
return new \Custom\UploadHandler([
'model' => $model,
'storage' => $this,
]);
}
} namespace Custom;
use RFM\Repository\Local\UploadHandler as LocalUploader;
class UploadHandler extends LocalUploader
{
public function validate($uploaded_file, $file, $error, $index)
{
$extension = pathinfo($file->name, PATHINFO_EXTENSION);
switch ($extension) {
case 'pdf':
$maxFileSize = 2000000;
break;
case 'doc':
$maxFileSize = 1000000;
break;
default:
$maxFileSize = $this->options['max_file_size'];
}
if ($maxFileSize && $file->size > $maxFileSize) {
$file->error = ['UPLOAD_FILES_SMALLER_THAN', [round($maxFileSize / 1000 / 1000, 2) . ' Mb']];
return false;
}
return parent::validate($uploaded_file, $file, $error, $index);
}
}
$local = new \Custom\Storage($config); instead of: $local = new \RFM\Repository\Local\Storage($config);
"autoload": {
"psr-4": {
"Custom\\": "connectors/php/customization"
}
} Don't forget to run Of course you can simply use include/require directives alternatively, without composer.
I found a nasty bug in the RFM plugin code, that doesn't allow to display server-side errors which happen while upload, see #305 (kind of ones that fires in the extended UploadHandler class). I have just fixed this bug and it will be included into the next release. But for now you have to clone/dowload the latest version of RFM from the GOOD LUCK |
One more note. The If you don't want to set a general upload limit you can set this option to $config=[];
$config['upload']['fileSizeLimit'] = false;
$local = new \Custom\Storage($config); |
Thank you very much, master. I'm totally new with all of this (the plugin, github, composer...), even with some of the php used too. Learning everyday. Greetings from the Canaries. |
Sure, good luck in learning |
In raising this issue, I confirm the following (please check boxes):
I use the following server-side connector (check one):
My familiarity with the project is as follows (check one):
Is it possible? To set up a filesize limit in bytes by different file types?
It would be useful. For example, one size limit for images, another one for videos, etc.
Thanks.
The text was updated successfully, but these errors were encountered: