CB Auto action to move a file
- GUEST
Does anyone have an example of a CB auto action PHP Method to copy or move a file.
We are using the file upload type field so users can upload a resume/cv.
I want to rename that file after upload adding a prefix of the users [firstname]_[lastname]_existingfilename.suffix
I have a FIELD action working on AftreUserUpdate and that adds the prefix to the field value fine.
So now just need the PHP to go in the new CODE auto action to check if file exists and if so MOVE it jfile::move giving it a name based on users name
Our resume field is called cb_resume
Here's what I've been trying in the PHP box and RETURN is set to SILENT
But page just crashes with no output so my syntax must be wrong
Ideally we want to just grab the file extension (doc, docx, or pdf) and then add that after the [userid] so an example would be
jonathan_appleton_478.pdf
On future uploads we'd like to try and clean out previous files too but want to focus on getting this first bit working
Thanks in advance for any advice.
Jonathan
Please Log in or Create an account to join the conversation.
- krileon
- ONLINE
- Posts: 68609
- Thanks: 9108
- Karma: 1434
Please understand we are not here to write custom code for you. Examples of how to move or rename files are just standard PHP. You can find several tutorials for PHP regarding renaming, moving, etc.. This is not CB specific beyond plugging in the data via substitutions or finding the locations.
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Please Log in or Create an account to join the conversation.
- GUEST
THANK YOU so much...... I will try this today
I know you aren't here to offer customised code but I just needed that helping hand to show me what was possible and correct syntax as I had no idea you could use $user-> set $user->store etc as would have written it all from scratch.
I spent over 6 hours attempting various things yesterday going around in circles....
That code probably took you ten minutes as you are the CB guru so I THANK YOU SO MUCH.
I want to delete previous versions of the file upload as well as have noticed that the file upload doesnt do that so I can probably do that now using a onbeforeupdate type action to grab the old filename.
PLEASE DO PM me if you have a paypal email address I can send you some beer money to!
you've really been very helpful
Thanks again
Jonathan
Please Log in or Create an account to join the conversation.
- krileon
- ONLINE
- Posts: 68609
- Thanks: 9108
- Karma: 1434
Code actions have access to $trigger, $user, and $vars variables. The $vars variable actually has direct access to the variables sent by the trigger as well and if set to be references under parameters can actually be modified by reference. There's a lot of nifty usages that can come of this.I know you aren't here to offer customised code but I just needed that helping hand to show me what was possible and correct syntax as I had no idea you could use $user-> set $user->store etc as would have written it all from scratch.
It's using a rename so you don't need to worry about duplicate copies of a file. The old file anytime a profile is updated is also automatically deleted when a new file is uploaded so there should be no issues with leftover files. If it's not cleaning up old files please let me know and will take a look at source to see if that process maybe failing.I want to delete previous versions of the file upload as well as have noticed that the file upload doesnt do that so I can probably do that now using a onbeforeupdate type action to grab the old filename.
Donations are always welcomed and appreciated. See the donation plan on the subscription tab of your profile. Glad I could helpPLEASE DO PM me if you have a paypal email address I can send you some beer money to!
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Please Log in or Create an account to join the conversation.
- GUEST
Is their any online documentation about all the CB functions etc you can use... $trigger, $user, and $vars
I'll test this out tomorrow
Please Log in or Create an account to join the conversation.
- krileon
- ONLINE
- Posts: 68609
- Thanks: 9108
- Karma: 1434
Thank youBeer money just donated thanks again!
Unfortunately no, not at this time. $trigger is the auto action object and $user is the CB user object built from the trigger. $vars however contains var1, var2, var3, etc.. as an array which outputs each variable sent to the trigger. So $vars gives you whatever the first variable is for the trigger used. This can be useful if lets say the trigger has an object you want to manipulate by reference. You could in theory do $vars->set( 'name', $value ); type usage.Is their any online documentation about all the CB functions etc you can use... $trigger, $user, and $vars
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Please Log in or Create an account to join the conversation.