public function UploadFiles()
 {
     $this->uploadDirectory = $this->GetUploadDirectory();
     $this->resultJson["fileUploadResults"] = array();
     foreach ($this->files as $file) {
         $this->currentFile = new \Library\Core\BO\FileUploadResult($file["tmp_name"]);
         //Init object
         $document = $this->InitDocumentObject();
         //Check if file exist before adding a row in DB
         $this->currentFile->setFilePath($this->uploadDirectory . "/" . $document->document_value());
         \Library\Core\DirectoryManager::CreateDirectory($this->uploadDirectory);
         $fileExists = \Library\Core\DirectoryManager::FileExists($this->currentFile->filePath());
         $this->currentFile->setDoesExist($fileExists);
         //Add document to DB
         if (!$fileExists) {
             //Don't add the document in DB if already added
             $this->AddDocumentToDatabase($document);
             //Add document to uploads directory
             $uploaded = $this->UploadAFile($this->currentFile->tmpFilePath(), $this->currentFile->filePath());
             $this->currentFile->setIsUploaded($uploaded);
         } else {
             $this->currentFile->setIsUploaded(false);
         }
         array_push($this->resultJson["fileUploadResults"], $this->currentFile);
     }
     return $this->resultJson;
 }
 /**
  * Location specific PDF document requirement
  * Copies the file which is passed to it, with 
  * the generated name
  */
 public function copyWithFile($object, $file)
 {
     if ($object instanceof \Library\Interfaces\IDocument) {
         $object->setFilename($this->GetFileNameToSaveInDatabase($file));
         $fileExists = \Library\Core\DirectoryManager::FileExists($this->GetUploadDirectory($object) . "/" . $object->Filename());
         $extensions = $object->ValidExtensions();
         if (is_array($extensions)) {
             $validExtension = $this->CheckExtension($file, $extensions);
         } else {
             $validExtension = true;
         }
         if (!$fileExists && $validExtension) {
             \Library\Core\DirectoryManager::CreateDirectory($this->GetUploadDirectory($object));
             $object->setContentSize($this->GetSizeInKb($file));
             $object->setContentType($this->GetExtension($file));
             //LEt's copy the file
             if (copy($file['tmp_name'], $this->GetUploadDirectory($object) . '/' . $object->Filename())) {
                 return parent::add($object);
             }
         } else {
             return -1;
         }
     }
 }