public function UploadFiles() { $this->uploadDirectory = $this->GetUploadDirectory(); $this->resultJson["fileUploadResults"] = array(); foreach ($this->files as $file) { $this->currentFile = new \Puzzlout\Framework\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()); \Puzzlout\Framework\Core\DirectoryManager::CreateDirectory($this->uploadDirectory); $fileExists = \Puzzlout\Framework\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 \Puzzlout\Framework\Interfaces\IDocument) { $object->setFilename($this->GetFileNameToSaveInDatabase($file)); $fileExists = \Puzzlout\Framework\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) { \Puzzlout\Framework\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; } } }