Topic: Radomize Image Title
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?
You are not logged in. Please login or register.
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:
// Hay subida compadre...
if ($up) {past UNDER that
//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
$clear = substr_replace($alnum, '', -3); // sin extension ni puntoreplace with
$clear = genRandomString($max_name);
//$clear = substr_replace($alnum, '', -3); // sin extension ni puntoAnd your done, I commented as must as I could s you can understand what its doing.
If there are any more questions, just ask.
So you just want to change the file-name, That is doable.
find:// Hay subida compadre... if ($up) {past UNDER that
//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
$clear = substr_replace($alnum, '', -3); // sin extension ni puntoreplace with
$clear = genRandomString($max_name); //$clear = substr_replace($alnum, '', -3); // sin extension ni puntoAnd 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!
Last edited by karma23 (2010-06-11 15:47:52)
gamerlv wrote:So you just want to change the file-name, That is doable.
find:// Hay subida compadre... if ($up) {past UNDER that
//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
$clear = substr_replace($alnum, '', -3); // sin extension ni puntoreplace with
$clear = genRandomString($max_name); //$clear = substr_replace($alnum, '', -3); // sin extension ni puntoAnd 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.
Powered by PunBB, supported by Informer Technologies, Inc.
Powered by PunBB