Code

Added check to avoid multiple uploads of the same file
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Jan 2006 09:03:08 +0000 (09:03 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 25 Jan 2006 09:03:08 +0000 (09:03 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2572 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_glpiAttachmentPool.inc

index bddbe307344d16f6f2e706c8beb1d9b7794146f9..896ed980bb6407af1f6a73f3dd47c8c22ab5e4d0 100644 (file)
@@ -133,16 +133,20 @@ class glpiAttachmentPool extends plugin
               print_red(_("Missing directory '/etc/gosa/glpi/' to store glpi uploads."));
             }else{
               $filen = "/etc/gosa/glpi/".$FILE['name'];
-              $fh = fopen($filen,"w");
-              if(!$fh){
-                print_red(sprintf(_("Can't create file '%s'."),$filen));
+              if(file_exists($filen)){
+                print_red(_("There is already a file with the same name uploaded."));
               }else{
-                $str = file_get_contents($FILE['tmp_name']);
-                fwrite($fh,$str,strlen($str));
-                fclose($fh);
-                $this->mime     = $FILE['type'];   
-                $this->filename = $FILE['name'];   
-              }
+                $fh = fopen($filen,"w");
+                if(!$fh){
+                  print_red(sprintf(_("Can't create file '%s'."),$filen));
+                }else{
+                  $str = file_get_contents($FILE['tmp_name']);
+                  fwrite($fh,$str,strlen($str));
+                  fclose($fh);
+                  $this->mime     = $FILE['type'];   
+                  $this->filename = $FILE['name'];   
+                }
+              } // File already exists
             }
           } // Check if any error occured
         } // check if valid filename was uploaded