Ejemplo n.º 1
0
 public function uploadFileAction()
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     //$projectId = $this->params()->fromQuery('projectId');
     //$taskId = $this->params()->fromQuery('taskId');
     $projectId = $this->getRequest()->getPost('projectId');
     $taskId = $this->getRequest()->getPost('taskId');
     $langId = $this->getRequest()->getPost('langId');
     //var_dump($projectId);
     //var_dump($taskId);exit;
     $entityManager = $this->getEntityManager();
     $project = $entityManager->find('\\User\\Entity\\Project', (int) $projectId);
     $task = $entityManager->find('\\User\\Entity\\Task', (int) $taskId);
     $lang = $entityManager->find('\\User\\Entity\\Language', (int) $langId);
     if (!empty($_FILES)) {
         $tempPath = $_FILES['file']['tmp_name'];
         $name = $_FILES['file']['name'];
         // added rand number to prevent errors if users upload same named files
         $token = "" . time() . rand(11, 99);
         $uploadPath = 'public/uploads' . DIRECTORY_SEPARATOR . $token . basename($name);
         move_uploaded_file($tempPath, $uploadPath);
         $file = new File();
         $file->setData(['name' => $_FILES['file']['name'], 'path' => $uploadPath, 'token' => $token, 'size' => $_FILES['file']['size'], 'time' => time(), 'project' => $project, 'task' => $task, 'language' => $lang]);
         $file->save($this->getEntityManager());
         $answer = ['file' => $file->getData(), 'success' => true];
         $json = json_encode($answer);
         echo $json;
         die;
     } else {
         $answer = ['success' => false];
         $json = json_encode($answer);
         die($json);
     }
 }
Ejemplo n.º 2
0
 public function uploadFileAction()
 {
     if (!empty($_FILES)) {
         $tempPath = $_FILES['file']['tmp_name'];
         $name = $_FILES['file']['name'];
         $uploadPath = 'public/uploads' . DIRECTORY_SEPARATOR . $name;
         move_uploaded_file($tempPath, $uploadPath);
         $file = new File();
         $file->setData(['name' => $_FILES['file']['name'], 'path' => $uploadPath, 'size' => $_FILES['file']['size'], 'time' => time()]);
         $file->save($this->getEntityManager());
         $answer = ['file' => $file->getData(), 'success' => true];
         $json = json_encode($answer);
         echo $json;
         die;
     } else {
         $answer = ['success' => false];
         $json = json_encode($answer);
         die($json);
     }
 }
Ejemplo n.º 3
0
 public function getData()
 {
     return ['id' => $this->id, 'name' => $this->name, 'file' => $this->file ? $this->file->getData2() : null, 'language' => $this->language->getData(), 'rate' => $this->rate, 'rate_freelancer' => $this->rate_freelancer, 'quantity' => $this->quantity, 'unit' => $this->unit, 'total' => $this->total, 'total_freelancer' => $this->total_freelancer, 'of_freelancer' => $this->of_freelancer];
 }