• Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space

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