• 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.

Auto Increment 001, 002, 003...

ferrisealge

New Member
I was wondering how I could change the code from the below forum discussion so that the Steven King example give you 001, 002, 003... at the end of the file name. Right now it just give me 1, 2, 3... I am sure this is something simple but can not seem to get it to work. Thanks guys!

**apparently I can not post a link so maybe a simple search of "stevenking1" will show you the post I am talking about. Thanks!
 
Hmmm, that's from Fabrik 2.1, and the upload code has changed a lot since then. And we never did add an option to generate the file name with eval'ed PHP. And as you can see from that discussion, this isn't a simple issue.

So in short ... no, there is not currently a way to do this. I'd still like to add a feature to allow using some custom PHP to name the file, but unless someone is prepared to fund the time to implement it (an hour or so's work), it's not likely to happen "real soon now".

Unless felix feels like having another go at it. :)

-- hugh
 
That was a while ago.... There was some hacking involved then but I can't remember the exact reason why. I vaguely remember something was conflicting doing alternative approaches. As Hugh mentioned the upload code has changed a lot in all those years and indeed so has Fabrik.

There is a much easier way now using the PHP form plugin. I have some code here which does some of what you want but I will need to add an extra line to allow PHP to add he zeros, probably with sprintf.

I'll post some code later as I'll document it at he same time.
 
Thanks! I was able to get some of the old code working to replicate what felixkat did in 2011. I could not figure out how to get the "00" in front of the number but was able to make the numbers start at "10." I need to have the uploaded files save to a directory in the order they were uploaded-starting with "10" gets me at least 89 in a row which should be enough for now. No rush on that code but it seems like it would be a nice thing to have.

Thanks again for the help guys.
 
Alright, I think I figured it out. I was able to use the old felixkat code modification to get the uploaded file name changed to the same thing upon upload based on a user generated field. Then I changed the code in:

fabrik / components / com_fabrik / helpers / uploader.php

(line 259) to

public static function incrementFileName($origFileName, $newFileName, $version)
{
if (JFile::exists($newFileName))
{
// splits the filename into pieces
$bits = explode('.', $newFileName);
// gets the file extension
$ext = array_pop($bits);
// puts the filename back together without the extension
$f = implode('.', $bits);
// Format the number ($version - 1) as a string with three characters, padding with '0' if necessary
$formerVersionFormatted = sprintf("%03d", $version - 1);
$newVersionFormatted = sprintf("%03d", $version);
// removes the version number from the end of the filename
$f=JString::rtrim($f,$formerVersionFormatted);
// adds the new version, a period, then the extension to the end of the filename
$newFileName = $f . $newVersionFormatted . "." . $ext;
// Increment the version number
$version++;
// Run this same thing over again with (version + 1) until the file does not exist.
$newFileName = self::incrementFileName($origFileName, $newFileName, $version);
}
return $newFileName;
}
This appears to be working for me. Wooo.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top