a-ok Posted June 20, 2016 Posted June 20, 2016 I'm curious to know if this is possible. I'd like to write a hook that upon adding an image to a specific page it will rename the image to the name of the page it's been/being uploaded to? I have a bank of images all with really useless filenames but would like to sort this upon uploading each one. Each image is added in a repeater with a corresponding colour (Pagefield), for example: I wonder if I could write a hook that would take each image in the repeater and rename each one something like pagetitle_01_charcoal pagetitle_02_red What do you think? Is it possible to write a hook to change a filename? Either on save or as it's uploading? Any advice/help is appreciated.
netcarver Posted June 20, 2016 Posted June 20, 2016 John, I've not done this before so I don't know for sure - but I'd guess at something like InputfieldImage::___fileAdded() - link.
adrian Posted June 20, 2016 Posted June 20, 2016 You could use this module: http://modules.processwire.com/modules/process-custom-upload-names/ Or if it looks too heavy for your needs, grab some code from it: Admin InputfieldFile::fileAdded - https://github.com/adrianbj/CustomUploadNames/blob/master/ProcessCustomUploadNames.module#L97 Frontend API calls Pagefile::install - https://github.com/adrianbj/CustomUploadNames/blob/master/ProcessCustomUploadNames.module#L101 2
a-ok Posted June 20, 2016 Author Posted June 20, 2016 3 hours ago, adrian said: You could use this module: http://modules.processwire.com/modules/process-custom-upload-names/ Or if it looks too heavy for your needs, grab some code from it: Admin InputfieldFile::fileAdded - https://github.com/adrianbj/CustomUploadNames/blob/master/ProcessCustomUploadNames.module#L97 Frontend API calls Pagefile::install - https://github.com/adrianbj/CustomUploadNames/blob/master/ProcessCustomUploadNames.module#L101 Thanks for this, adrian. Really useful. 1
adrian Posted June 20, 2016 Posted June 20, 2016 Glad it helps - if you want some extended reading, here is the post that spawned my module: Lots of interesting reading on those file/image hooks. 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now