if (empty($_FILES[$files_key]['tmp_name'])) { $body['code'] = 30109; $body['message'] = '没有文件上传。'; $headers['setCommonHeader'](); $app['http']->response->setStatus(200); $app['http']->response->setBody($app['encoder']->encode($body)); $app['http']->stop(); } /* 创建上传组件相关对象 */ $storage = new \Upload\Storage\FileSystem($files_uploads, true); $file = new \Upload\File($files_key, $storage); $data = array(); $i = 0; $k = 0; /* 文件上传数量限制 */ if ($file->count() > 5) { $error = '已到最大数量了!'; $body['code'] = 30109; $body['message'] = $error; $headers['setCommonHeader'](); $app['http']->response->setStatus(200); $app['http']->response->setBody($app['encoder']->encode($body)); $app['http']->stop(); } $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/jpeg')), new \Upload\Validation\Size('5M')))->beforeValidate(function ($fileInfo) use($file) { /* 文件上传失败,捕获错误代码 */ if ($file->getErrors()) { $error = $file->getErrors(); $body['code'] = 30109; $body['message'] = $error; $headers['setCommonHeader']();