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

index 81e1d5c59b5578ed8eb3c4d813248405a4d75db5..50eeeb6437be2723992eff9dedb92c2e4168c1aa 100644 (file)
--- a/core.php
+++ b/core.php
@@ -1,16 +1,20 @@
 <?php
 function save_file ($file, $name){
-    //Generate a random set of numbers to set in front of the filename
-    $rand_string = crc32(microtime(true).mt_rand(1000, 9000));
+    //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/';
-    //Remove any tags
-    $file_data=strip_tags($file);
-    //Put together the random string+filename
-    $file_name=$rand_string.'_'.$name;
     //Move the file to the above location with said filename
-    move_uploaded_file($file_data,$path.$file_name);
+    move_uploaded_file($file,$path.$file_name);
     //Return url+filename to the user
     echo 'http://a.uguu.se/'.$file_name;
 }
+Function gen_name ($in){
+    $chars = 'abcdefghijklmnopqrstuvwxyz';
+    $name = '';
+    for ($i = 0; $i < 6; $i++) {
+    $name .= $chars[mt_rand(0, 25)];
+    }
+    return $name.'_'.$in;
+}
 ?>