Only call fclose if resource is still available

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-11-08 18:55:48 +01:00
parent 733f17d59a
commit aee5fb7a98

View File

@@ -157,8 +157,13 @@ class FileService implements IAttachmentService {
$target = $folder->newFile($fileName);
$content = fopen($file['tmp_name'], 'rb');
if ($content === false) {
throw new StatusException('Could not read file');
}
$target->putContent($content);
if (is_resource($content)) {
fclose($content);
}
$attachment->setData($fileName);
}
@@ -175,8 +180,13 @@ class FileService implements IAttachmentService {
$target = $this->getFileForAttachment($attachment);
$content = fopen($file['tmp_name'], 'rb');
if ($content === false) {
throw new StatusException('Could not read file');
}
$target->putContent($content);
if (is_resource($content)) {
fclose($content);
}
$attachment->setLastModified(time());
}