0
* $name - A unique version of the given $name.
0
function unique_filename($name, $num = 2) {
0
- if (file_exists(MAIN_DIR.Config::current()->uploads_path.$name)) {
0
- $name = explode(".", $name);
0
- # Handle "double extensions"
0
- foreach (array("tar" => "gz", "tar" => "bz", "tar" => "bz2") as $first => $second)
0
- if ($name[count($name) - 2] == $first and end($name) == $second) {
0
- $name[count($name) - 2] == $first.".".$second;
0
- unset($name[count($name) - 1]);
0
+ if (!file_exists(MAIN_DIR.Config::current()->uploads_path.$name))
0
+ $name = explode(".", $name);
0
- $ext = ".".array_pop($name);
0
+ # Handle "double extensions"
0
+ foreach (array("tar.gz", "tar.bz", "tar.bz2") as $extension) {
0
+ list($first, $second) = explode(".", $extension);
0
+ $file_first =& $name[count($name) - 2];
0
+ if ($file_first == $first and end($name) == $second) {
0
+ $file_first = $first.".".$second;
0
- $try = implode(".", $name)."-".$num.$ext;
0
- if (!file_exists(MAIN_DIR.Config::current()->uploads_path.$try))
0
+ $ext = ".".array_pop($name);
0
- return unique_filename(implode(".", $name).$ext, $num + 1);
0
+ $try = implode(".", $name)."-".$num.$ext;
0
+ if (!file_exists(MAIN_DIR.Config::current()->uploads_path.$try))
0
+ return unique_filename(implode(".", $name).$ext, $num + 1);
0
function upload($file, $extension = null, $path = "", $put = false) {
0
$file_split = explode(".", $file['name']);
0
+ $original_ext = end($file_split);
0
+ # Handle "double extensions"
0
+ foreach (array("tar.gz", "tar.bz", "tar.bz2") as $ext) {
0
+ list($first, $second) = explode(".", $ext);
0
+ $file_first =& $file_split[count($file_split) - 2];
0
+ if ($file_first == $first and end($file_split) == $second) {
0
+ $file_first = $first.".".$second;
0
+ array_pop($file_split);
0
$file_ext = end($file_split);
0
if (is_array($extension)) {
0
- if (!in_array(strtolower($file_ext), $extension)
) {
0
+ if (!in_array(strtolower($file_ext), $extension)
and !in_array(strtolower($original_ext), $extension)) {
0
for ($i = 0; $i < count($extension); $i++) {
0
if (($i + 1) != count($extension)) $comma = ", ";
0
if (($i + 2) == count($extension)) $comma = ", and ";
0
- $list.= "
*.".$extension[$i].$comma;
0
+ $list.= "
<code>*.".$extension[$i]."</code>".$comma;
0
- error(__("
Error"), _f("Only %s files are supported.", array($list)));
0
+ error(__("
Invalid Extension"), _f("Only %s files are supported.", array($list)));
0
- } elseif (isset($extension) and $file_ext != $extension and $file_ext != strtoupper($extension))
0
- error(__("Error"), _f("Only %s files are supported.", array("*.".$extension)));
0
+ } elseif (isset($extension) and strtolower($file_ext) != strtolower($extension) and strtolower($original_ext) != strtolower($extension))
0
+ error(__("Invalid Extension"), _f("Only %s files are supported.", array("*.".$extension)));
0
array_pop($file_split);
0
$file_clean = implode(".", $file_split);