• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Radomize Image Title

karma23

Chevereto Noob
I would like the image title to be completely randomized when a user uploads an image. I don't know php very well, can someone please help?
 
So you just want to change the file-name, That is doable.
find:
Code:
// Hay subida compadre...
        if ($up) {
past UNDER that
Code:
            //gen random name by Gamerlv
            function genRandomString($length=10,$timestamp=0) {
                $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; //the char we use
                $len = strlen($characters) - 1; //get the total length(ammount of characters) of $characters
                $string = ""; //init the output string

                for ($p = 0; $p < $length; $p++) {
                    $string .= $characters[mt_rand(0, $len)]; //add a character to the string, until we have $length 
                }
                if ($timestamp){
                    $string .= "-".date("j-m-y\:H:i:s"); // add timestamp !warning this does not account for the max char
                }            
                return $string; //output the string.
            }

then find
Code:
$clear = substr_replace($alnum, '', -3); // sin extension ni punto
replace with
Code:
$clear = genRandomString($max_name);
            //$clear = substr_replace($alnum, '', -3); // sin extension ni punto
And your done, I commented as must as I could s you can understand what its doing.
If there are any more questions, just ask.
 
gamerlv said:
So you just want to change the file-name, That is doable.
find:
Code:
// Hay subida compadre...
        if ($up) {
past UNDER that
Code:
            //gen random name by Gamerlv
            function genRandomString($length=10,$timestamp=0) {
                $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; //the char we use
                $len = strlen($characters) - 1; //get the total length(ammount of characters) of $characters
                $string = ""; //init the output string

                for ($p = 0; $p < $length; $p++) {
                    $string .= $characters[mt_rand(0, $len)]; //add a character to the string, until we have $length 
                }
                if ($timestamp){
                    $string .= "-".date("j-m-y\:H:i:s"); // add timestamp !warning this does not account for the max char
                }            
                return $string; //output the string.
            }

then find
Code:
$clear = substr_replace($alnum, '', -3); // sin extension ni punto
replace with
Code:
$clear = genRandomString($max_name);
            //$clear = substr_replace($alnum, '', -3); // sin extension ni punto
And your done, I commented as must as I could s you can understand what its doing.
If there are any more questions, just ask.

This worked perfectly. Thank you so much!

One question though, is it possible to reduce the length of the file name? I tried changing the $lenth variable, but it doesn't seem to have any effect. I'd like it to be a maximum of 6 characters or maybe even less. I removed the numbers and added capital letters to the available characters, since my website is hosted on a linux server it is case sensitive, so that gives it more to work with...

Thanks again!
 
karma23 said:
gamerlv said:
So you just want to change the file-name, That is doable.
find:
Code:
// Hay subida compadre...
        if ($up) {
past UNDER that
Code:
            //gen random name by Gamerlv
            function genRandomString($length=10,$timestamp=0) {
                $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; //the char we use
                $len = strlen($characters) - 1; //get the total length(ammount of characters) of $characters
                $string = ""; //init the output string

                for ($p = 0; $p < $length; $p++) {
                    $string .= $characters[mt_rand(0, $len)]; //add a character to the string, until we have $length 
                }
                if ($timestamp){
                    $string .= "-".date("j-m-y\:H:i:s"); // add timestamp !warning this does not account for the max char
                }            
                return $string; //output the string.
            }

then find
Code:
$clear = substr_replace($alnum, '', -3); // sin extension ni punto
replace with
Code:
$clear = genRandomString($max_name);
            //$clear = substr_replace($alnum, '', -3); // sin extension ni punto
And your done, I commented as must as I could s you can understand what its doing.
If there are any more questions, just ask.

This worked perfectly. Thank you so much!

One question though, is it possible to reduce the length of the file name? I tried changing the $lenth variable, but it doesn't seem to have any effect. I'd like it to be a maximum of 6 characters or maybe even less. I removed the numbers and added capital letters to the available characters, since my website is hosted on a linux server it is case sensitive, so that gives it more to work with...

Thanks again!


Nevermind, I figured it out. Works great, thanks!
 
Ok, I'm glad you found it.

For anyone else using this ( I know there will be others).
You can edit the length of the filename in the config.php, the $max_name variable. When using this there is no limit on how long they can get, I tested it to a amount of 220 charters.
 
Back
Top