diff --git a/inside/Concert.php b/inside/Concert.php index 113109c..3702dbe 100644 --- a/inside/Concert.php +++ b/inside/Concert.php @@ -142,8 +142,9 @@ class Concert { $this->id = getNextId("program"); if($_FILES['userfile']['error'] != 4){ $temp_name = new_file($_FILES['userfile'], "program"); - rename_file($temp_name, $this->id, "program"); - $this->picture = $this->id.substr($temp_name, -4); + rename_file($temp_name, $this->id, "program"); + $ext = strtolower( pathinfo($temp_name, PATHINFO_EXTENSION) ); + $this->picture = $this->id . "." . $ext; } else { $this->picture = "0"; } diff --git a/inside/functions.php b/inside/functions.php index 119419b..a5b7964 100644 --- a/inside/functions.php +++ b/inside/functions.php @@ -449,22 +449,21 @@ function new_file($file, $dir) { } function rename_file($old_name, $id, $dir, $report = true) { - if ($dir == 'products') { - $dir = 'images/products/'; - }else { - $dir = "../../public_html/bilder/$dir/"; - } + if ($dir == 'products') + $dir = 'images/products/'; + else + $dir = "../../public_html/bilder/$dir/"; - $old_name = $dir.$old_name; - $new_name = $dir.$id.substr($old_name, -4); + $ext = strtolower( pathinfo($old_name, PATHINFO_EXTENSION) ); + $old_name = $dir . $old_name; + $new_name = $dir . $id . "." . $ext; deleteFile($new_name, false); - if (rename($old_name, $new_name)) { + + if (rename($old_name, $new_name)) return true; - } else { - if ($report == true) { + if ($report == true) error("Could not rename file."); - } return false; } }