Topic: Random Filenames

Hi guys

I love this script, can't wait for more features, is there a way of the script generating a random filename once the image has been uploaded instead of using the exact filename.

I uploaded logo.png for example and the link provided had http://www.sitename/logo.png

Is there a way of doing this like TinyPic.com

Thanks

Thumbs up

Re: Random Filenames

Look up in engine.php this:

// Limpiemos el nombre
            // --> Tambien me quedo "super rico".
            $lower = strtolower($tmp_name); // Solo minusculas
            $alnum = ereg_replace("[^[:alnum:]]","",$lower); // Solo alfanumericos
            if ($exten==peg) { unset($exten); $exten = 'jpg'; }
            $clear = substr_replace($alnum, '', -3); // sin extension ni punto
            // Cortemos el nombre (si hace falta)
            $conteo = strlen($clear);
 
            // Random
            $ch_1 = chr(rand(ord("a"), ord("z")));
            $ch_2 = chr(rand(ord("z"), ord("a")));
 
            if ($conteo>$max_name) {
                $renombre = substr("$clear", 0, $max_name);
            } else {
                if (empty($clear)) {
                    $renombre = $ch_1.$ch_2.$ch_1;
                } else {
                    $renombre = $clear;
                }
            }
 
            // Si existe el nombre, renombramos el que estamos subiendo.
            if (file_exists(DIR_IM.$renombre.'.'.$exten)) {
                if ($conteo>$totalchars) {
                    // Si el nombre es muy largo, corta
                    $renombra = substr("$renombre", 0, $max_name-4); // 4 -> El remplazo de mas abajo           
                } else {
                    $renombra = $renombre;   
                }
                // Vamos a darle caracteres aleatorios.           
                $name = $renombra.$ch_1.$ch_2.$ch_1.'.'.$exten;
            } else {
                $name = $renombre.'.'.$exten;
            }

That is all the "name thing". If you want some changes you must take care of:
- What happens if the file already exists?
- What kind of rename should i use?

So, try to make your way trhought that code, is not too hard.

rodolfoberrios.com | PLEASE use Tech Support forums to ask for support!

Re: Random Filenames

Rodolfo wrote:

Look up in engine.php this:

// Limpiemos el nombre
            // --> Tambien me quedo "super rico".
            $lower = strtolower($tmp_name); // Solo minusculas
            $alnum = ereg_replace("[^[:alnum:]]","",$lower); // Solo alfanumericos
            if ($exten==peg) { unset($exten); $exten = 'jpg'; }
            $clear = substr_replace($alnum, '', -3); // sin extension ni punto
            // Cortemos el nombre (si hace falta)
            $conteo = strlen($clear);
 
            // Random
            $ch_1 = chr(rand(ord("a"), ord("z")));
            $ch_2 = chr(rand(ord("z"), ord("a")));
 
            if ($conteo>$max_name) {
                $renombre = substr("$clear", 0, $max_name);
            } else {
                if (empty($clear)) {
                    $renombre = $ch_1.$ch_2.$ch_1;
                } else {
                    $renombre = $clear;
                }
            }
 
            // Si existe el nombre, renombramos el que estamos subiendo.
            if (file_exists(DIR_IM.$renombre.'.'.$exten)) {
                if ($conteo>$totalchars) {
                    // Si el nombre es muy largo, corta
                    $renombra = substr("$renombre", 0, $max_name-4); // 4 -> El remplazo de mas abajo           
                } else {
                    $renombra = $renombre;   
                }
                // Vamos a darle caracteres aleatorios.           
                $name = $renombra.$ch_1.$ch_2.$ch_1.'.'.$exten;
            } else {
                $name = $renombre.'.'.$exten;
            }

That is all the "name thing". If you want some changes you must take care of:
- What happens if the file already exists?
- What kind of rename should i use?

So, try to make your way trhought that code, is not too hard.

I would but I don't speak Spanish!!!

Thumbs up

Re: Random Filenames

Wacky wrote:
Rodolfo wrote:

So, try to make your way trhought that code, is not too hard.

I would but I don't speak Spanish!!!

Then learn, is the most beautiful language.
ALSO.. you can check the functions and see what they do. belive me, is not hard and you could learn some basic php thing that you can use in several ways!.

rodolfoberrios.com | PLEASE use Tech Support forums to ask for support!

Re: Random Filenames

Rodolfo wrote:
Wacky wrote:

I would but I don't speak Spanish!!!

Then learn, is the most beautiful language.

big_smile That is really true.

But still, it would help to make the comments a bit "Englisher". ;-)

Greets
Ammler

Thumbs up

Re: Random Filenames

never mind i figured out my probleum

Last edited by Thomas (2009-06-29 11:11:59)

Thumbs up