• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Custom File/Foler Name

I am attempting to make a custom folder and file name for a file upload.

I would like to accomplish this type of file name.

'EMPLOYEE ACTIVE/'.$last_int.'/'.$last_name.' '.$first_name.'/{thistable___state} {thistable___certification_type} {thistable___expiration}' ;

The code I have tried in the rename file name is below.. However my understanding that is for the file name and not the location of the file.

$last_name= '{employees___last_name}';
$first_name= '{employees___first_name}';
$last_int = $last_name[0];
$last_int = strtoupper($last_int);
$last_name= strtoupper($last_name);
$first_name= strtoupper($first_name);
$path= 'EMPLOYEE ACTIVE/'.$last_int.'/'.$last_name.' '.$first_name.'/{thistable___state} {thistable___certification_type} {thistable___expiration}' ;
// use Joomla file utils
jimport( 'joomla.filesystem.file' );
// get the original file and split it into parts
$old = ($formModel->formData['file']);
$oldParts = pathinfo($old);
// in this example we're using the id as the new filename
$sid = $formModel->formData['id'];
//create the new file (path and name)
$new = $oldParts['dirname'].'/'.$sid.'.'.$oldParts['extension'];
// update the file itself
JFile::move(JPATH_SITE.$old, JPATH_SITE.$new);
// update the data
$formModel->updateFormData('file', $new, true);
// update the db
$object = new stdClass();
// Must be a valid primary key value.
$object->id = $sid;
// new path + name
$object->file = $new;
// Update the data in the db
$result = JFactory::getDbo()->updateObject('ep_submission', $object, 'id');
 
Nope, that won't work. As the tooltip on the rename option says, that code can only change the filename, not the path, and should just return the name. Also, it runs before we've moved the file from the web server's temporary upload folder to the element's configured folder, so if you try and move it, our code is then going to fail. Also, as it runs before the form data is written to the database, your updateObject() will fail as there's no object to update yet.

Currently there's really no way to do this from the file element itself.

You might be able to do it in a PHP form submission plugin, running onAfterProcess, which checks $_FILES[] (or $app->input-files) to see if something was uploaded, then do something similar to what your code is doing - move it, then update the row in the database. But i can't really help much with that on a standard sub, that's custom coding work.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top