Beispiel #1
1
 /**
  * Загружает файл на сервер переданный через XHR
  * @param string $post_filename Название поля с файлом в массиве $_GET
  * @param string $allowed_ext Список допустимых расширений (через запятую)
  * @param string $allowed_size Максимальный размер файла (в байтах)
  * @param string $destination Папка назначения (внутри пути upload)
  * @return array
  */
 public function uploadXHR($post_filename, $allowed_ext = false, $allowed_size = 0, $destination = false)
 {
     $cfg = cmsConfig::getInstance();
     $user = cmsUser::getInstance();
     $dest_size = 10;
     //$this->getXHRFileSize();
     if (!$dest_size) {
         return array('success' => false, 'error' => LANG_UPLOAD_ERR_NO_FILE);
     }
     $dest_name = files_sanitize_name($_GET['qqfile']);
     $dest_info = pathinfo($dest_name);
     $dest_ext = $dest_info['extension'];
     if ($allowed_ext !== false) {
         $allowed_ext = explode(",", $allowed_ext);
         foreach ($allowed_ext as $idx => $ext) {
             $allowed_ext[$idx] = trim($ext);
         }
         if (!in_array($dest_ext, $allowed_ext)) {
             return array('error' => LANG_UPLOAD_ERR_MIME, 'success' => false, 'name' => $dest_name);
         }
     }
     if (!$destination) {
         $user->increaseFilesCount();
         $dest_dir = $this->getUploadDestinationDirectory();
         $dest_file = substr(md5($user->id . $user->files_count . microtime(true)), 0, 8) . '.' . $dest_ext;
         $destination = $dest_dir . '/' . $dest_file;
     } else {
         $destination = $cfg->upload_path . $destination . '/' . $dest_file;
     }
     return $this->saveXHRFile($destination, $dest_name, $dest_size);
 }
Beispiel #2
0
 /**
  * Загружает файл на сервер переданный через XHR
  * @param string $post_filename Название поля с файлом в массиве $_GET
  * @param string $allowed_ext Список допустимых расширений (через запятую)
  * @param string $allowed_size Максимальный размер файла (в байтах)
  * @param string $destination Папка назначения (внутри пути upload)
  * @return array
  */
 public function uploadXHR($post_filename, $allowed_ext = false, $allowed_size = 0, $destination = false)
 {
     $user = cmsUser::getInstance();
     $dest_name = files_sanitize_name($_GET['qqfile']);
     $dest_ext = pathinfo($dest_name, PATHINFO_EXTENSION);
     if (!$this->checkExt($dest_ext, $allowed_ext)) {
         return array('error' => LANG_UPLOAD_ERR_MIME, 'success' => false, 'name' => $dest_name);
     }
     if ($allowed_size) {
         if ($this->getXHRFileSize() > $allowed_size) {
             return array('error' => sprintf(LANG_UPLOAD_ERR_INI_SIZE, files_format_bytes($allowed_size)), 'success' => false, 'name' => $dest_name);
         }
     }
     $dest_file = substr(md5(uniqid() . microtime(true)), 0, 8) . '.' . $dest_ext;
     if (!$destination) {
         $user->increaseFilesCount();
         $destination = $this->getUploadDestinationDirectory() . '/' . $dest_file;
     } else {
         $destination = cmsConfig::get('upload_path') . $destination . '/' . $dest_file;
     }
     return $this->saveXHRFile($destination, $dest_name);
 }