Blame view

app-wx/modules/user/controllers/DefaultController.php 1.49 KB
62d73041   xu   app-wx
1
2
<?php

ab931159   xu   app-wx(v0.1.0 bui...
3
namespace app\wx\modules\user\controllers;
62d73041   xu   app-wx
4

3a892ee0   xu   app-wx(v0.1.0 bui...
5

62d73041   xu   app-wx
6
use Yii;
3a892ee0   xu   app-wx(v0.1.0 bui...
7
use common\helpers\ImageManager;
62d73041   xu   app-wx
8
9
10
11
12
13
14
15
16
17
18
19
20
use stdClass;

/**
 * 控制器
 */
class DefaultController extends BaseController
{

    /**
     * 首页
     */
    public function actionIndex()
    {
3a892ee0   xu   app-wx(v0.1.0 bui...
21
22
        $params = ['isGuest' => Yii::$app->getUser()->isGuest];
        return $this->render('index', $params);
62d73041   xu   app-wx
23
    }
cf6f0119   xu   app-wx(v0.1.0 bui...
24
25
26
27
28
29
30
31
32
33
34
35

    /**
     * 上传文件
     * @return string
     */
    public function actionUploadFile()
    {
        $e = new stdClass();
        $e->success = false;
        $e->message = 'ok';
        $userId = 0;

1de3211f   xu   app-wx(v0.1.0 bui...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        if (empty($_FILES["file"])) {
            $e->message = '文件为空';
            return $this->renderJson($e);
        }
        if (empty($_FILES["file"]['tmp_name'])) {
            $e->message = '文件为空';
            return $this->renderJson($e);
        }
        $type = $_FILES["file"]["type"];
        $typeArr = explode('/', $type);
        if ('image' !== $typeArr[0]) {
            $e->message = '只能上传 png, jpg 等文件';
            return $this->renderJson($e);
        }
cf6f0119   xu   app-wx(v0.1.0 bui...
50
51

        $uploadInfo = ImageManager::uploadImg($_FILES["file"]);
1de3211f   xu   app-wx(v0.1.0 bui...
52
        $filename = $uploadInfo[0];
cf6f0119   xu   app-wx(v0.1.0 bui...
53
        $tmpUrl = $this->site->base_url.'/'.$uploadInfo[2];
1de3211f   xu   app-wx(v0.1.0 bui...
54
        $tmpMinFile = $this->site->base_url.'/'.$uploadInfo[3];
cf6f0119   xu   app-wx(v0.1.0 bui...
55
56

        $e->success = true;
1de3211f   xu   app-wx(v0.1.0 bui...
57
        $e->tmpFile = $filename;
cf6f0119   xu   app-wx(v0.1.0 bui...
58
59
60
61
62
        $e->tmpMinUrl = $tmpMinFile;
        $e->tmpUrl = $tmpUrl;
        $e->message = 'ok';

        return $this->renderJson($e);
1de3211f   xu   app-wx(v0.1.0 bui...
63
    }
cf6f0119   xu   app-wx(v0.1.0 bui...
64
65

} 
3a892ee0   xu   app-wx(v0.1.0 bui...

cf6f0119   xu   app-wx(v0.1.0 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

cf6f0119   xu   app-wx(v0.1.0 bui...

1de3211f   xu   app-wx(v0.1.0 bui...

62d73041   xu   app-wx