Jump to content

Custom image upload path per template and/or field?


ttbb
 Share

Recommended Posts

In PW all images are uploaded under /site/assets/files/pageID
to match a bunch of media of an old website i'd like to integrate customizable upload subfolders for different templates or fields like:
/site/assets/blog-images/pageID/ or /site/assets/portfolio/pageID/hero-images/ and /site/assets/portfolio/pageID/detail-images/

i've found the ProcessCustomUploadNames module ( https://processwire.com/modules/process-custom-upload-names/ ), but this only can change the file names, not the upload path.

then i found this, but i'm not sure about it being helpful in this case:


is there a hook which can eventually intervene when i'm uploading an image?

Link to comment
Share on other sites

i did some additional research and ended with having the idea to check the $pages->saveFieldReady() hook as a place where i could change the upload path (https://processwire.com/api/ref/pages/save-field-ready/).

i'm not sure whether or when this event happens when i upload an image: is the upload action itself (choosing an image via file dialog or drag and drop) already starting the upload a save process for an image file or is this happening when save the entire page? where can i find informations about the detailed file/image upload process?

maybe the WireUpload class (https://processwire.com/api/ref/wire-upload/) can be useful here? especially the WireUpload::setDestinationPath() method? (https://processwire.com/api/ref/wire-upload/set-destination-path/)

has anyone built something similar already?

Edited by ttbb
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...