From 153aaf88db7086e4143cb429362845ae0ab52092 Mon Sep 17 00:00:00 2001 From: Neku Date: Sat, 4 Jan 2014 02:01:25 +0100 Subject: fixed some shit --- static/upload.php | 39 +++++++++++++++++++-------------------- 1 file 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 * -- cgit v1.2.3