upload custom directory plugin - move images

11 posts by 3 authors in: Forums > CMS Builder
Last Post: December 30, 2022   (RSS)

By Dave - December 22, 2022

Hi Jeff, 

Sorry for the delay.  Did you figure this out yet?  If you're still working on it check out this function in /lib/upload_functions.php

// Returns the absolute uploadDir and uploadUrl for a specific upload field. This is determined by: The dir/url of the CMS,
// .. the (potentially relative) upload dir/url in settings, and the (potentially defined) custom upload dir/url for the field.
// Usage: list($uploadDir, $uploadUrl) = getUploadDirAndUrl($fieldSchema);
function getUploadDirAndUrl($fieldSchema, $settingsUploadDir = null, $settingsUploadUrl = null, $returnOnErrors = false) {

It'll get you the full path and URL for uploads.

Let me know if you have any other questions.  Thanks!

Dave Edis - Senior Developer
interactivetools.com

That is what I was looking for, thanks Dave.

But I do have a question. It would be good if the plugin could hook the section editor to detect a change in the custom directory and provide the option to move files right then and there. Is there a way to hook the section editor?

Right now my issue is there is no way to detect that the custom directory has been changed and now using the settings['uploadDir'] or new custom directory. 

Any thoughts appreciated.

Jeff Shields

By Dave - December 30, 2022

Hi Jeff, 

What's the end objective or problem you're trying to solve?  

If it's to allow the users to change the custom upload folders you could have a plugin that runs when that folder is changed.  Or a general plugin that scans the upload table and checks all the files.  If they're not in the expected folder it could look for them in the default folder and move them.

Let me know some more details and I'll try to help.

Thanks!

Dave Edis - Senior Developer
interactivetools.com

The end objective of my plugin is to move files to the appropriate directories when the custom directory is changed in the section editor.

I have my plugin working by manually entering old directory and new directory in AdminUI.

What plugin hook should I use to trigger it when saving the change? Is it:

addAction('section_preDispatch', 'moveFileOnCustomDirectorChange');
Jeff Shields

I just figured it out

Jeff Shields

Hey Jeff,

Care to share?

Happy New Year!

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Once I have it ready, I will donate it to the community

Jeff Shields

By gkornbluth - December 30, 2022 - edited: December 30, 2022

Appreciate it,

Sounds like a useful plugin.

I'm sorry that the some of the user submitted plugins have disappeared from the IT site.

I'm going to go through the ones I have and make sure to add them to the CMSB Cookbook Site as well

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - December 30, 2022

Hi Jerry, 

>I'm sorry that the some of the user submitted plugins have disappeared from the IT site.

You can find the user-submitted ones here.  If there's any you want that we don't have let me know.

https://www.interactivetools.com/plugins/?User-Submitted-9

Thanks!

Dave Edis - Senior Developer
interactivetools.com