src/Controller/TemporaryJsonapiFileFieldUploader.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Controller/TemporaryJsonapiFileFieldUploader.php b/src/Controller/TemporaryJsonapiFileFieldUploader.php index 6a97710..a33d8af 100644 --- a/src/Controller/TemporaryJsonapiFileFieldUploader.php +++ b/src/Controller/TemporaryJsonapiFileFieldUploader.php @@ -4,6 +4,7 @@ namespace Drupal\jsonapi\Controller; use Drupal\Component\Utility\Bytes; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\Environment; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Field\FieldDefinitionInterface; @@ -335,8 +336,8 @@ class TemporaryJsonapiFileFieldUploader { fclose($temp_file); } else { - // Close the file streams. - fclose($temp_file); + // Close the input file stream since we can't proceed with the upload. + // Don't try to close $temp_file since it's FALSE at this point. fclose($file_data); $this->logger->error('Temporary file "%path" could not be opened for file upload.', ['%path' => $temp_file_path]); throw new HttpException(500, 'Temporary file could not be opened'); @@ -463,7 +464,11 @@ class TemporaryJsonapiFileFieldUploader { $settings = $field_definition->getSettings(); // Cap the upload size according to the PHP limit. - $max_filesize = Bytes::toInt(file_upload_max_size()); + // @todo Remove when we stop supporting Drupal 8.5 and 8.6. + $max_bytes = floatval(\Drupal::VERSION) < 8.7 + ? file_upload_max_size() + : Environment::getUploadMaxSize(); + $max_filesize = Bytes::toInt($max_bytes); if (!empty($settings['max_filesize'])) { $max_filesize = min($max_filesize, Bytes::toInt($settings['max_filesize'])); }