summaryrefslogtreecommitdiff
path: root/static/upload.php
diff options
context:
space:
mode:
authorNeku <neku@pomf.se>2014-01-04 02:01:25 +0100
committerNeku <neku@pomf.se>2014-01-04 02:01:25 +0100
commit153aaf88db7086e4143cb429362845ae0ab52092 (patch)
treecc52895bfd32d4f998dbf63ae43f1cd7e279c1f7 /static/upload.php
parent5f096b12ff830b734c499443dc608fde5bbd407d (diff)
fixed some shit
Diffstat (limited to 'static/upload.php')
-rw-r--r--static/upload.php39
1 files changed, 19 insertions, 20 deletions
diff --git a/static/upload.php b/static/upload.php
index 61388fd..643eb84 100644
--- a/static/upload.php
+++ b/static/upload.php
@@ -11,32 +11,31 @@ include_once 'includes/database.inc.php';
* @return string
*/
function generate_name ($file) {
- // We start at N retries, and --N until we give up
- $tries = POMF_FILES_RETRIES;
- // We rip out the extension using pathinfo
- // TODO: figure out a solution for .tar.gz and similar files? This has now been ghetto fixed, read below!
- $ext = pathinfo($file->name, PATHINFO_EXTENSION);
- do {
- // If we run out of tries, throw an exception. Should be caught and JSONified.
- if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name');
-
- // TODO: come up with a better name generating algorithm
- $newname = ''; // Filename Generator:
- $newname .= chr(mt_rand(ord("z"), ord("a"))); // + random lowercase letter
+ // We start at N retries, and --N until we give up
+ $tries = POMF_FILES_RETRIES;
+ // We rip out the extension using pathinfo
+ // TODO: figure out a solution for .tar.gz and similar files? This has now been ghetto fixed, read below!
+ $ext = pathinfo($file->name, PATHINFO_EXTENSION);
+ do {
+ // If we run out of tries, throw an exception. Should be caught and JSONified.
+ if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name');
+
+ // TODO: come up with a better name generating algorithm
+ $newname = ''; // Filename Generator:
$newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
- $newname .= chr(mt_rand(ord("z"), ord("a"))); // + random lowercase letter
$newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
- $newname .= chr(mt_rand(ord("z"), ord("a"))); // + random lowercase letter
- $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
- // To add a dot or not after a file which has no extension
- if ($ext != '') $newname .= '.' . $ext;
+ $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
+ $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
+ $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
+ $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter
+ // To add a dot or not after a file which has no extension
+ if ($ext != '') $newname .= '.' . $ext;
- } while (file_exists(POMF_FILES_ROOT . $newname)); // TODO: check the database instead?
+ } while (file_exists(POMF_FILES_ROOT . $newname)); // TODO: check the database instead?
- return $newname;
+ return $newname;
}
-
/**
* Handles the uploading and db entry for a file
*