# Change default image directory

**URL:** <https://forum.getkirby.com/t/change-default-image-directory/10487>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 25, 2018, 7:02am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487 "2018-05-25T07:02:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 7:02am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/1 "2018-05-25T07:02:40Z")

</div>

By default, all images for a page should be added to their respective directories in the content directory. However, in my structure, all images are in an images directory in the asset folder. Now if I add a new image through a panel in a specific page it is being added in the page directory in the content folder not in the image directory in the assets folder. How do I fix this?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 25, 2018, 8:27am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/2 "2018-05-25T08:27:30Z")

</div>

The assets folder is not intended to store user added files, but rather site wide images like a logo, icons etc… The only. way you could achieve that would be via a hook that moves an uploaded image to the assets folder. But you would have to link to such images manually and can’t use Kirby drag and drop functionality.

Why are you doing this? If you want to store all images in one place, you can either do so in the content folder (site options) or in a separate images folder in content.

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 9:23am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/4 "2018-05-25T09:23:03Z")

</div>

## This is my current directory structure

```
- assets
    -images
        -team
            //all team page images
        -about 
            //all about page images
- content
    -team
        team.txt
    -about
        about.txt

```

and I link all images using \<?php echo kirby()-\>urls()-\>assets . '/images/"any image name"' ?\>

## According to you, I should have a directory structure like this:-

```
- assets
- content
    -team
        team.txt
    -about
        about.txt
     -images
        -team
            //all team page images
        -about 
            //all about page images

```

1. How will I get the path to my images?
2. if a new image will be added from suppose the team page panel. it will not get inserted in the content/images/team directory rather it will go in content/team directory.

How do i fix these ?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 25, 2018, 9:33am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/5 "2018-05-25T09:33:19Z")

</div>

If you put them in different subdirectories, you might as well put them into the corresponding content folders. What is your reason for not doing this?

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 9:39am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/6 "2018-05-25T09:39:52Z")

</div>

I want to keep all my images in a single folder. The folder can have sub-directories or not but all images should be at the same parent location.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 25, 2018, 9:48am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/7 "2018-05-25T09:48:00Z")

</div>

In your template, you could the get the images like this:

```auto
<?php 
// fetch all images from /images/about
$images = page('images/about')->images();
foreach($images as $image):
 echo $image->url();
endforeach;

```

If you upload an image to content/team, it will get stored in that folder. To upload an image to the images/team folder, you would have to go into that folder. Or move the image from the content/team folder to the content/images/team folder via an [upload hook](https://getkirby.com/docs/developer-guide/advanced/hooks).

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 9:52am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/8 "2018-05-25T09:52:22Z")

</div>

Great ! Thanks for that.  
But one issue still prevails that if I add a new image from the about panel it will go into content/about and not in content/images/about. This code will fail then.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 25, 2018, 9:53am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/9 "2018-05-25T09:53:55Z")

</div>

See edited post above.

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 10:01am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/10 "2018-05-25T10:01:05Z")

</div>

Thank you I’ll look into that.  
One last thing can you modify the above code to access images from assets/images (if my images folder is in assets) .

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 10:07am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/11 "2018-05-25T10:07:00Z")

</div>

Also what will be the move logic in the the upload hook:

```auto
kirby()->hook('pane.file.upload', function($page) {
    //move logic here
})

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 25, 2018, 10:12am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/12 "2018-05-25T10:12:01Z")

</div>

You can’t use the same code as above for the assets folder. To use images from the assets folder in a similar way, you would have to read the images from. the folder, then create a new Asset for each file. Or just call a file manually, but that probably doesn’t make sense.

As for the code within the hook, maybe this helps: [https://gist.github.com/samnabi/f4ecb351f2ec2bd596e5](https://gist.github.com/samnabi/f4ecb351f2ec2bd596e5) You would have to adapt that, because you don’t want to shrink images, but it is a starting point.

---

<div class="post-metadata">

**Author:** ![themukul](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@themukul](https://forum.getkirby.com/u/themukul)\
**Post date:** [May 25, 2018, 10:16am UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/13 "2018-05-25T10:16:39Z")

</div>

Cool! Thanks for the help!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/change-default-image-directory/10487/14 "2025-02-06T17:28:11Z")

</div>


