summaryrefslogtreecommitdiffstats
path: root/application/models
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-06-08 17:11:28 +0200
committerFlorian Pritz <bluewind@xinu.at>2013-06-08 17:11:28 +0200
commitee6706a4ab8207fc2c007fc2069505b24873e780 (patch)
treee19c4c407b99b65f87e15aff8ed7111199802f22 /application/models
parentbeb6fdb72185fdc7dafee97426364c59178885e7 (diff)
mfile/new_id(): rewrite as loop and make min/max parameters
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/models')
-rw-r--r--application/models/mfile.php18
1 files changed, 12 insertions, 6 deletions
diff --git a/application/models/mfile.php b/application/models/mfile.php
index 0dd8d7b1e..27f05e46b 100644
--- a/application/models/mfile.php
+++ b/application/models/mfile.php
@@ -16,23 +16,29 @@ class Mfile extends CI_Model {
}
// Returns an unused ID
- function new_id()
+ function new_id($min = 3, $max = 6)
{
static $id_blacklist = NULL;
- $id = random_alphanum(3,6);
-
if ($id_blacklist == NULL) {
$id_blacklist = scandir(FCPATH);
$id_blacklist[] = "file";
$id_blacklist[] = "user";
}
- if ($this->id_exists($id) || in_array($id, $id_blacklist)) {
- return $this->new_id();
- } else {
+ $max_tries = 100;
+
+ for ($try = 0; $try < $max_tries; $try++) {
+ $id = random_alphanum($min, $max);
+
+ if ($this->id_exists($id) || in_array($id, $id_blacklist)) {
+ continue;
+ }
+
return $id;
}
+
+ show_error("Failed to find unused ID after $max_tries tries.");
}
function id_exists($id)