Not a bug XF\Service\Attachment\Preparer :: insertDataFromFile ignore some extra data keys.

truonglv

Well-known member
Affected version
2.1.0 b4
Hello.

PHP:
$extra = [
    'width' => $editor->getWidth(),
    'height' => $editor->getHeight()
];

$tempFile = File::copyAbstractedPathToTempFile($path);
File::deleteFromAbstractedPath($path);

$file = new FileWrapper($tempFile, $fileName);

$handler->beforeNewAttachment($file, $extra);
$data = $attachmentPreparer->insertDataFromFile($file, \XF::visitor()->user_id, $extra);

In some case I have provide width & height to attachment data but it's not saved cause you have forced that fields for image only.

PHP:
$sourceFile = $file->getFilePath();
$width = $file->getImageWidth();
$height = $file->getImageHeight();
 
The extra param is not for arbitrary data -- it's for the specific elements defined within the function (the file path and upload date).

You would need to approach this differently, though if you are storing a width and height for a non-image file, you may also be violating potential code assumptions.
 
Back
Top Bottom