Example #1
0
 /**
  * 接收多文件
  * @param array $files
  * @param config $config
  * @return array 返回上传成功的文件的保存路径
  */
 function receiveMultiFile($files, $config)
 {
     if (!is_writable(filesystem::path($config['path'])) || !is_dir(filesystem::path($config['path']))) {
         return UPLOAD_ERR_CANT_WRITE;
     }
     $index = 0;
     $path = array();
     while (isset($files['error'][$index])) {
         if ($files['error'][$index] == UPLOAD_ERR_OK) {
             if (!isset($config['size']) || $files['size'][$index] < $config['size']) {
                 $mimetype = filesystem::mimetype($files['tmp_name'][$index]);
                 if (!isset($config['type']) || in_array($mimetype, $config['type'])) {
                     $type = empty(filesystem::type($files['name'][$index])) ? 'tmpuploadfile' : filesystem::type($files['name'][$index]);
                     $filename = rtrim($config['path'], '/') . '/' . md5_file($files['tmp_name'][$index]) . sha1_file($files['tmp_name'][$index]) . '.' . $type;
                     if (move_uploaded_file($files['tmp_name'][$index], $filename)) {
                         $path[] = $filename;
                     }
                 }
             }
         }
         $index++;
     }
     return $path;
 }
Example #2
0
 /**
  * 获得国家图标
  */
 function getflag()
 {
     $id = $this->get->id;
     $flagModel = $this->model('flag');
     $flag = $flagModel->get($id);
     if (!empty($flag)) {
         $mimetype = filesystem::mimetype($flag['file']);
         $this->response->addHeader('Content-Type', $mimetype);
         readfile($flag['file']);
     } else {
         $this->response->addCode(302);
         $this->response->addHeader('Location', $this->http->url('index', '__404'));
     }
 }