Ejemplo n.º 1
0
 public function singleuploadAction()
 {
     $form = new \FileUpload\Form\SingleUpload('file-form');
     if ($this->getRequest()->isPost()) {
         // Postback
         $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($data);
         if ($form->isValid()) {
             $formData = $form->getData();
             $originalName = $formData['file']['name'];
             $newName = htmlentities(strip_tags(str_replace(array(' '), array('_'), $formData['file']['name'])));
             if (!file_exists($this->fileUploadService->getUploadPath() . $newName)) {
                 if (rename($this->fileUploadService->getUploadTempPath() . $originalName, $this->fileUploadService->getUploadPath() . $newName)) {
                     $fileObj = new \FileUpload\Entity\File();
                     $fileObj->setFileName($newName);
                     $fileObj->setFilePath($this->fileUploadService->getUploadPath());
                     $fileObj->setFileType($formData['file_type']);
                     $fileObj->setUpdatedAt(new \DateTime());
                     $this->fileUploadService->getDb()->persist($fileObj);
                     $this->fileUploadService->getDb()->flush();
                 }
             } else {
                 $this->flashMessenger()->addMessage('Die Datei ist vorhanden!!');
                 return $this->redirect()->toRoute('file-upload', array('action' => 'index'));
             }
             $this->flashMessenger()->addMessage('Datei ist erfolgreich hochgeladen!!');
             return $this->redirect()->toRoute('file-upload', array('action' => 'index'));
             return $this->redirectToSuccessPage($form->getData());
         }
     }
     $this->flashMessenger()->addMessage('Dateihochladen ist fehlgeschlagen!');
     return $this->redirect()->toRoute('file-upload', array('action' => 'index'));
 }
Ejemplo n.º 2
0
 protected function createNewFiles($file)
 {
     $uploadFiles = $this->getRequest()->getFiles()->toArray();
     $postData = $this->getRequest()->getPost()->toArray();
     if (isset($uploadFiles['sfartwork']) && count($uploadFiles['sfartwork'])) {
         if (!file_exists($this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName())) {
             mkdir($this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName() . '/');
         }
         foreach ($uploadFiles['sfartwork'] as $key => $uf) {
             $uFileType = array_shift($postData['sfartwork']);
             $uFile = new \FileUpload\Entity\File();
             $uFile->setFilePath($this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName() . '/');
             $uFile->setFileName($uf['file']['name']);
             $uFile->setFileType($uFileType['file_type']);
             $uFile->setRelPath($this->fileUploadService->getUploadPath() . $file->getStorage() . '/' . $file->getName() . '/');
             if (file_exists($this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName() . '/' . $uFile->getFileName())) {
                 $this->flashMessenger()->addMessage('Fehler: Die Datei ' . $uFile->getFileName() . ' konnte nicht geschrieben werden da sie bereits existiert. Bitte löschen Sie vor dem Upload die alte Datei und versuchen Sie es nochmal.');
                 return $this->redirect()->toRoute('sendefile', array('action' => 'editsendefile', 'id' => $file->getId()));
                 continue;
             }
             $relsult = rename($uf['file']['tmp_name'], $this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName() . '/' . $uFile->getFileName());
             exec('chmod 666 "' . $this->fileUploadService->getUploadPath() . $file->getStorage() . '/VA_FILES/' . $file->getName() . '/' . $uFile->getFileName() . '"');
             $this->fileService->getDb()->persist($uFile);
             $this->fileService->getDb()->flush($uFile);
             $file->getArtwork()->add($uFile);
         }
     }
 }