Store all images for all site in one folder?

Iā€™m moving my portfolio website from HTML files (and no CMS) to Kirby. I currently have all my images, for all the website, in one folder. I like the simplicity of this and being able to check all the images file sizes, or optimise all the images in one go, without having to open lots of different folders.

Is it possible in Kirby to put all the images and assets (PDFs etc) in one place, or will this create issues?

Shouldnā€™t be a problem, just point your files sections to a single parent. That parent would the contain all files.

Something like:

sections:
  files:
    label: All my files
    type: files
    parent: site.find('filestore')    

Then, have a filestore folder in your content folder and put everything there. (the name "filestore" is arbitrarily chosen, it could be anything).
Maybe also put a ā€œnope.txtā€ in that folder, then create an empty nope.php template, just to make sure people donā€™t try to access ā€œwww.yourwesbite.com/filestoreā€ā€¦ ("nope" was also arbitrarily chosen)

Maybe also put a ā€œnope.txtā€ in that folder, then create an empty nope.php template, just to make sure people donā€™t try to access ā€œ[www.yourwesbite.com/filestore](http://www.yourwesbite.com/filestore)ā€ā€¦

why would someone try to access this folder? So the folder filestore is also a web page someone could visit? What would they see or be able to do?

what would a nope.text and nope.php do?

Any folder is a page accessible through the browser.

There isnā€™t really a good reason someone would try to access it.
Itā€™s just that the files will ultimately be served under /media/pages/filestore/<somehash>/myimage.jpg, indicating that there is a filestore page.
If you then have some default template that gets applied to the filestore, you might do stuff in that default template to the page that you donā€™t really want.

Setting the template of filestore to ā€œnopeā€, and having an ā€œnopeā€ template, makes it so that if someone tries it, he just gets an empty page.

Any folder is a page accessible through the browser.

Okayā€¦ so I canā€™t simply have a folder, perhaps called ā€˜resourcesā€™ where I put all my images, without this becoming a web page www.xyz.com/resources

Exactly, all folders in the /content folder become a web page.

But if you put them somewhere else, they are not Kirby\Cms\File objects.

But if you put them somewhere else, they are not Kirby\Cms\File objects.

Is that a problem? Could I simply put my resources folder in the same folder that contains ā€˜contentā€™ ā€˜kirbyā€™ ā€˜mediaā€™ ā€˜siteā€™ etc?

Yes, but you wouldnā€™t be able to manage the files via the panel

But where is the problem with simply blocking access to the page with the files?

Unless you are using the same file in multiple locations, Iā€™d store them with the page they belong to, anyway, instead of in one central space.

Another option would be to store the files directly in the content folder (next to site.txt) as files of the $site object. Then you wouldnā€™t need a special page folder.

But where is the problem with simply blocking access to the page with the files?

Why would I need to bother to block access to the ā€˜resourcesā€™ folder/page?

How can I block access to this page?

Unless you are using the same file in multiple locations, Iā€™d store them with the page they belong to, anyway, instead of in one central space.

Argh, yes this could be an issue. Some images are used on different pages. So would this mean that I would be best off storing all my images in one folder?

Another option would be to store the files directly in the content folder (next to site.txt) as files of the $site object. Then you wouldnā€™t need a special page folder.

There are hundreds and I think this would make my content folder very messy and hard to find stuff?

Two options:

  1. What @rasteiner already suggested, by using a template which sends users to the error page if they happen to open this link.
  2. Use a route that does the same (no template needed)

It depends. If itā€™s just a few duplicate files, I personally wouldnā€™t worry and just upload them again to different places. Or do a mixture, upload files that are used multiple times to the site object, all others to the pages they belong to.

After all, searching through hundreds or thousands of images could also become a bottleneck.

I was wondering what that suggestion meant! So I create a nope.txt in that folder, then create an empty nope.php. So what do I write in the nope.txt file? What does an empty nope.php file mean? Literally with no code, blank file?

Nothing.

I think thatā€™s what @rasteiner meant, but I would actually send the user to the error page:

nope.php (Name is irrelevant, Iā€™d call the text file files.txt/files.php, not nope)

<?php
go('error');

As many of my images are used on multiple pages (and because I think it is neater) all my images are in one folder called ā€˜resourcesā€™.

I can create relative links to my images, which works fine, until I have child pages (/portfolio/case-study1), then the relative link obviously doesnā€™t work.

I donā€™t really want to create different relative links to images depending on where the page is in my site and absolute URLs while I am building the site locally is a total pain, so how do you link to images?

I guess the same problem is true with links between pages. Child pages would need a different relative link to parent pages?

Doing the following seems to work

src=ā€œ/resources/logo.svgā€

donā€™t know why

We always use Kirbyā€™s API to access the URL of pages and files:

<?= $page->url() ?>
<?= $file->url() ?>

The question is now if you have all files in one folder, how do you want refer to your files in your content. In a textarea field, in a blocks field, in a select field?

We always use Kirbyā€™s API to access the URL of pages and files:

What does that mean?

In my header I have a logo. How do I link to my logo image? So that the same link works on all pages regardless of whether the page is a parent or a child?

src=ā€œ/resources/logo.svgā€

Seems to work, but I have no idea why

The leading / means that it is an absolute path.

So if your site will always be directly in the web root, that works.
If, however, at some point you decide to move this site to a subfolder, like from www.mark-e.com to www.mark-e.com/archive, this will no longer work because it will try to load images from www.mark-e.com/resources instead of www.mark-e.com/archive/resources.

Kirby however always knows where it was installed. Thatā€™s why you could use:

src="<?= url('resources/logo.svg') ?>"

It will output a correct absolute URL.

1 Like

Nevertheless, the problem I see with this approach is that you usually probably will not want to hard-code (i.e. manually write ) your files names into your template (unless you want to output a gallery or something like that). Usually, your files would probably be included in your text or selected in a field, then rendered in your template from there?