Révision 2858c9fe
Ajouté par Jocelyn Delande il y a presque 11 ans
class/utils.class.php | ||
---|---|---|
63 | 63 |
} |
64 | 64 |
return $v; |
65 | 65 |
} |
66 |
|
|
67 |
public static function get_unique_filepath($path) { |
|
68 |
/** To handle uploads with same name : for a given path, suffix it with _<n> |
|
69 |
(keeping trailing extension) |
|
70 |
* till it find a non-preexistant_path and returns it. |
|
71 |
*/ |
|
72 |
if (file_exists($path)) { |
|
73 |
$info = pathinfo($path); |
|
74 |
$extension = $info['extension']; |
|
75 |
$remain = self::strip_extension($path); |
|
76 |
$n = 0; |
|
77 |
do { |
|
78 |
$n++; |
|
79 |
$fn = sprintf('%s_%d.%s', $remain, $n, $extension); |
|
80 |
} while (file_exists($fn)); |
|
81 |
return $fn; |
|
82 |
|
|
83 |
} else { |
|
84 |
return $path; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
66 | 88 |
} |
67 | 89 |
|
68 | 90 |
?> |
Formats disponibles : Unified diff
allow upload with same names