瀏覽代碼

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
     }
23
     }
24
 
24
 
25
     public static function handleUpload($file = false) {
25
     public static function handleUpload($file = false) {
26
+        $cwd = getcwd(); // Our websites CWD (Current working dir)
26
         $filename = $file['name']; // Get filename
27
         $filename = $file['name']; // Get filename
27
         $size = $file['size']; // Gets filesize
28
         $size = $file['size']; // Gets filesize
28
         $tempname = $file['tmp_name']; // Where did php upload our data to?
29
         $tempname = $file['tmp_name']; // Where did php upload our data to?
30
         $ext = explode('.', $file['name']); // end() doesnt like us using explode directly.
31
         $ext = explode('.', $file['name']); // end() doesnt like us using explode directly.
31
         $extension = strtolower(end($ext)); // Get the extension of the file.
32
         $extension = strtolower(end($ext)); // Get the extension of the file.
32
         $randomname = Upload::generateRandomString(); // We give our file a random name - It will be this.
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
         $uploadPath = $cwd .'/'. Config::$file_path . $randomname . '.' . $extension;
42
         $uploadPath = $cwd .'/'. Config::$file_path . $randomname . '.' . $extension;
36
 
43
 
37
         if (!in_array($extension, Config::$file_types)) {
44
         if (!in_array($extension, Config::$file_types)) {

Loading…
取消
儲存