api/src/Topxia/Api/Resource/Upload.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Topxia\Api\Resource;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;

class Upload extends BaseResource
{
    public function post(Application $app, Request $request, $group)
    {
        if ($request->getMethod() != 'POST') {
            return $this->error('404', 'only allow post!');
        }
        try {
            $file = $request->files->get('file');
            if (empty($file)) {
                return $this->error('404', '没有添加上传文件!');
            }
            $record = $this->getFileService()->uploadFile($group, $file);
            $url = $this->getFileUrl($record['uri']);
        } catch (\Exception $e) {
            return $this->error('500', '上传文件失败!');
        }

        return array(
                'code' => '200',
                'message' => $url
        );
    }

    protected function getFileService()
    {
        return $this->getServiceKernel()->createService('Content:FileService');
    }

    public function filter($res)
    {
        return $res;
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。