Similar to this: https://www.drupal.org/node/2090585
^ though, this is Drupal 7
I'm writing a custom file widget, which extends the core FileWidget, that splits files into chunks so that I don't need to increase upload_max_filesize or post_max_size in my php.ini. It works, and the file is successfully uploaded and saved as a file entity with a file ID, but when trying to save that file ID into the field, it refuses to do it. The field settings allow files up to 500 MB, but because the file module is checking for the server's max upload size, it rejects the file, even though it already exists and is referenced in the database.
If there is a way to do this without changing core, I haven't been able to figure it out. I have already tried removing the validators in my widget's formElement() function, as well as using the hook mentioned in the linked post to unset the file_validate_size validator via hook_field_widget_form_alter.
It seems like even if I remove the validator for file size, getUploadValidators() still gets called from the file constraint validate() function. I wonder, what was the point of the file_validate_size validator if the constraint checked for this anyway?
public function validate($value, Constraint $constraint) {
// Get the file to execute validators.
$file = $value->get('entity')->getTarget()->getValue();
// Get the validators.
$validators = $value->getUploadValidators();
// Checks that a file meets the criteria specified by the validators.
if ($errors = file_validate($file, $validators)) {
foreach ($errors as $error) {
$this->context->addViolation($error);
}
}
}
Above is the function in FileValidationConstraintValidator.php that performs the getUploadValidators() that makes this impossible. The function getUploadValidators() is called from FileWidget.php (but not FileItem.php) and ImageItem.php (but not ImageWidget.php).
I hope that someone out there is as confused as I am why things are this way, or that a core change can make this possible. Or, maybe I'm missing something?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | bypass_php_limit_on_file_field-2764413-9.patch | 1.04 KB | maticb |
Comments
Comment #8
maticb commentedI needed this to, I ended up patching the core file module to bypass the php setting and force field setting for a specific field, since I didn't wanna bother with any field settings forms, but my patch could be extended to check a new widget setting instead
Comment #9
maticb commentedComment #10
maticb commentedComment #15
chrisckRan into this issue today trying to upload large videos via FTP and using File Field Sources file attach to link the file on the server to a media entity. Ideally we would like to keep the php file size limit intact and use FTP for larger files.