コード例 #1
0
 public function uploadAction()
 {
     if ($_FILES['add_file']['size'] > 10485760) {
         echo 3;
         exit;
     }
     setlocale(LC_ALL, 'ru_RU.UTF-8');
     $filesModel = new Files();
     $fileName = basename($_FILES['add_file']['name']);
     $filesId = $filesModel->insert(array('projects_id' => 0, 'tasks_id' => 0, 'filename' => $fileName));
     $uploadDir = dirname(dirname(dirname(__DIR__))) . '/data/userfiles/';
     $uploadFile = $uploadDir . $filesId;
     if (move_uploaded_file($_FILES['add_file']['tmp_name'], $uploadFile)) {
         $this->session->setUploadedFiles(array($filesId));
         echo 1;
     } else {
         if (isset($_FILES['add_file']['error'])) {
             echo 'Error: ' . $_FILES['add_file']['error'];
         } else {
             echo 2;
         }
     }
     exit;
 }