AndrewSimm
Well-known member
I have an articles add-on that I am using with @digitalpoint Cloudflare add-on. Thus far my add-on correctly uploads the article image file to R2 without any change of code. Where I am stuck is how to display the image in the template. Below is my php code. Any insight on how to display this correctly in my template so the URL is correct?
PHP:
$abstractedPath = \XF::app()->config('externalDataPath');
$abstractedThumbPath = \XF::app()->config('externalDataPath');
$upload = $this->request->getFile('image', false);
if($upload)
{
$abstractedPath .= '://articles/'. $thread_id . '/' . $upload->getFileName();
\XF\Util\File::copyFileToAbstractedPath($upload->getTempFile(), $abstractedPath);
//Upload articles image
$tempFile = $upload->getTempFile();
$image = \XF::app()->imageManager()->imageFromFile($tempFile);
if($image->getheight() / $image->getwidth() > 0.75)
{
throw $this->exception($this->error(\XF::phrase('andrew_articles_image_ratio_not_supported')));
}
$maxWidth = $this->options()->andrewArticlesImageWidth;
$image->resize($maxWidth, $maxHeight = null);
$image->save($tempFile, $format = null, $quality = null);
\XF\Util\File::copyFileToAbstractedPath($tempFile, $abstractedPath);
//Create thumbnail that displays in profile
$abstractedThumbPath .= '://articles/'. $thread_id . '/' . '/thumb-' . $upload->getFileName();
$maxWidth = $this->options()->andrewArticlesImageThumbWidth;
$image->resizeAndCrop($maxWidth, $maxHeight = null);
$image->save($tempFile, $format = null, $quality = null);
\XF\Util\File::copyFileToAbstractedPath($tempFile, $abstractedThumbPath);
//Save files
$save->image_url = $thread_id . '/' . $upload->getFileName();
$save->thumb_url = $thread_id . '/thumb-' . $upload->getFileName();
unlink($tempFile);