]> jfr.im git - uguu.git/commitdiff
Update core.php
authorEric Johansson (neku) <redacted>
Wed, 11 Feb 2015 02:49:57 +0000 (03:49 +0100)
committerEric Johansson (neku) <redacted>
Wed, 11 Feb 2015 02:49:57 +0000 (03:49 +0100)
core.php

index 6f380dbf65d349d7a004515f2cdf874a98134f55..3cc509bd81fb6253f75025a7c85a6e7b5f684196 100644 (file)
--- a/core.php
+++ b/core.php
@@ -1,23 +1,25 @@
 <?php
 function save_file ($file, $name){
-    //Generate a random prefix, strip tags and remove any whitespace
-    $file_name = gen_name(strip_tags(preg_replace('/\s+/', '', $name)));
     //Where to save
     $path='/home/neku/www/files/';
+    //Generate prefix, put together name and remove tags/whitespace
+    $file_name = strip_tags(preg_replace('/\s+/', '', $name));
+    $file_name = gen_name(file_name);
+    while(file_exists($path.$file_name)){
+        $file_name = gen_name(file_name);
+    }
     //Move the file to the above location with said filename
     move_uploaded_file($file,$path.$file_name);
     //Return url+filename to the user
     echo 'http://a.uguu.se/'.$file_name;
 }
 Function gen_name ($in){
-    //Check so the file doesn't exist, and generate random prefix
-    while(file_exists('/home/neku/www/files'.$name.'_'.$in)){
+    //Generate random prefix
     $chars = 'abcdefghijklmnopqrstuvwxyz';
     $name = '';
     for ($i = 0; $i < 6; $i++) {
     $name .= $chars[mt_rand(0, 25)];
         }
-    }
     return $name.'_'.$in;
 }
 ?>