Skip to content

修改上传结果响应格式

Compare
Choose a tag to compare
@moxuandi moxuandi released this 06 Aug 03:27
· 11 commits to master since this release

使用Yii2 Response响应:

$response = Yii::$app->response;
$response->format = Response::FORMAT_JSON;
$response->data = [
    'original' => $upload->realName,  // 原始文件名, eg: 'img_6.jpg'
    'title' => $upload->fileName,      // 新文件名, eg: '171210_054500_8166.jpg'
    'url' => $upload->fullName,  // 返回的地址, eg: '/uploads/image/201712/171210_054500_8166.jpg'
    'size' => $upload->fileSize,       // 文件大小, eg: 108527
    'type' => '.' . $upload->fileExt,  // 文件类型, eg: '.jpg'
    'state' => $upload->stateInfo,     // 上传状态, 上传成功时必须返回'SUCCESS'
];
$response->send();