Преглед на файлове

Check if file exists, and if it does roll a new filename.

tags/rls1
kenn408k преди 6 години
родител
ревизия
06d56c36d5
променени са 1 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. 9
    2
      classes/upload.class.php

+ 9
- 2
classes/upload.class.php Целия файл

@@ -23,6 +23,7 @@ class Upload {
23 23
     }
24 24
 
25 25
     public static function handleUpload($file = false) {
26
+        $cwd = getcwd(); // Our websites CWD (Current working dir)
26 27
         $filename = $file['name']; // Get filename
27 28
         $size = $file['size']; // Gets filesize
28 29
         $tempname = $file['tmp_name']; // Where did php upload our data to?
@@ -30,8 +31,14 @@ class Upload {
30 31
         $ext = explode('.', $file['name']); // end() doesnt like us using explode directly.
31 32
         $extension = strtolower(end($ext)); // Get the extension of the file.
32 33
         $randomname = Upload::generateRandomString(); // We give our file a random name - It will be this.
33
-
34
-        $cwd = getcwd(); // Our websites CWD (Current working dir)
34
+        
35
+        // If filename exists, we roll a new one.
36
+        while (IS_FILE($cwd .'/'. Config::$file_path . $randomname . '.' . $extension)) {
37
+            $randomname = Upload::generateRandomString();
38
+        }
39
+        
40
+        // We got our unique filename, lets continue.
41
+        
35 42
         $uploadPath = $cwd .'/'. Config::$file_path . $randomname . '.' . $extension;
36 43
 
37 44
         if (!in_array($extension, Config::$file_types)) {

Loading…
Отказ
Запис