Jump to content

Hook to change uploaded image(s) filename


a-ok
 Share

Recommended Posts

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:

Screen Shot 2016-06-20 at 13.46.33.png

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.

Link to comment
Share on other sites

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

  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
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

×
×
  • Create New...