Where is my error? (a silly doubt issue, excuseme)

Hi, I started to create a site with Kirby a couple of weeks ago and I have a very simple question: how can I show a dynamic image? I have created a field in a .txt file with “Work main image” and coded this template:

  <div class="work-img-container">

    <?php if ($mainImage = $page->work_main_image()): ?>
        <img src="<?= $mainImage->url() ?>" class="work-image">
    <?php endif ?>


but it doesn’t work. I don’t understand how Kirby shows images in templates enough. I managed to create a dynamic field with text, but images are for now for me a problem.


See: Files | Kirby CMS

Thanks, but I’ve used the toFile method in other attempts, but the image doesn’t charge. If I inspect the element, I see the URL, but if I go to there, Kirby crashes, and the debug send me a message:

Exception thrown with message “The directory “E:\Websites\kirby\art_portfolio/media/pages/works/luana-reads” cannot be created”

#12 Exception in E:\Websites\kirby\art_portfolio\kirby\src\Filesystem\Dir.php:392
#11 Kirby\Filesystem\Dir:make in E:\Websites\kirby\art_portfolio\kirby\src\Filesystem\Dir.php:387
#10 Kirby\Filesystem\Dir:make in E:\Websites\kirby\art_portfolio\kirby\src\Filesystem\F.php:158
#9 Kirby\Filesystem\F:copy in E:\Websites\kirby\art_portfolio\kirby\src\Cms\Media.php:83
#8 Kirby\Cms\Media:publish in E:\Websites\kirby\art_portfolio\kirby\src\Cms\FileActions.php:267
#7 Kirby\Cms\File:publish in E:\Websites\kirby\art_portfolio\kirby\src\Cms\Media.php:56
#6 Kirby\Cms\Media:link in E:\Websites\kirby\art_portfolio\kirby\config\routes.php:73
#5 Kirby\Http\Route:{closure} in [internal]:0
#4 Closure:call in E:\Websites\kirby\art_portfolio\kirby\src\Http\Router.php:120
#3 Kirby\Http\Router:call in E:\Websites\kirby\art_portfolio\kirby\src\Cms\App.php:340
#2 Kirby\Cms\App:call in E:\Websites\kirby\art_portfolio\kirby\src\Cms\App.php:1238
#1 Kirby\Cms\App:render in E:\Websites\kirby\art_portfolio\index.php:5
#0 require in E:\Websites\kirby\art_portfolio\kirby\router.php:14

Is the media folder writable? Can you see any other files there? Usually, the Panel checks that when you install it.

No, it’s only for reading, I changed it but something turn it back only for reading. I’ll investigate it.

Kirby (or more correctly the Apache user) needs to be able to write to some folders (content, media, site/accounts, site/cache), otherwise it won’t work.

Yes, that is, but I don’t solve the problem yet. To develop my site locally I have installed PHP through Xampp. Initially, that worked well and the site went on, but someday it crashed and until now I look for a solution every day.

How I can give permission to Apache users to write to some folders in Windows?

Haven’t worked in a Windows environments in ages, but maybe this helps:

1 Like

Thanks, but I gave up to fix the error and decide to change to the Apple environment.