Blame view

src/app/frontend/controllers/IndexController.php 1.93 KB
ef60cd4d   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  <?php
  
  namespace controllers;
  
  class IndexController extends \Phalcon\Mvc\Controller
  {
      ///////////////////////////////////////////////////////////////////////////
  
  
      public function indexAction()
      {
         // die(print_r($_SESSION['user-id']));
          if($_SESSION['user-id']){
              $user_id = $_SESSION['user-id'];
              $user = \users::findFirst(array("id = $user_id"));
              $role = \usersServices::find();
  
              $this->view->setVars([
                  'role' => $role,
                  'user' => $user
              ]);
          }
  
  
      }
  
  
      public function downloadImagesAction()
      {
  
          if ($this->request->hasFiles() == true) {
  
              $data['directory'] = $this->request->getPost('directory' );
  
              foreach ($this->request->getUploadedFiles() as $file){
  
                  $allowed_filetypes = array('.jpg','.JPG', '.png', '.PNG', '.gif', '.GIF');
  
                  $ext = substr($file->getName() ,strpos($file->getName() ,'.'),strlen($file->getName() )-1);
  
                  if(!$data['directory']) {
                      $data['directory'] = md5(microtime());
                  }
  
  
                  if(in_array($ext,$allowed_filetypes))
                  {
                      $image_path = $this->storage->getEmailTemplatePath( 'temp', $data['directory']);
  
                      if(!file_exists($image_path))
                      {
                          mkdir( $image_path, 0777, true );
                      }
                      $file->moveTo($image_path.$file->getName());
                      $data['message'] = 'Загрузка файла '.$file->getName().' выполнена успешно.';
                  } else {
                      $data['message'] = 'Произошла ошибка. Не верный формат файла.';
                  }
                  $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
  
  
                  echo json_encode($data);
  
  
              }
          }
      }
  }