Article From:https://www.cnblogs.com/wangzhaobo/p/9970882.html

In fact, it’s not just the Yii framework that can be used, because it’s just a class library that can be used in any framework.

preparation in advance

1.Register with Qiniu at https://portal.qiniu.com/signup/choice

2.Create a space https://portal.qiniu.com/bucket (remember the name of the storage space and the storage area)

3.Create the secret key https://portal.qiniu.com/user/key

 

Step one:

Add “crazyfd/yii2-qiniu” to the require attribute in composer.json: “dev-master”

The second step:

 Perform composer update in the root directory

The third step:

    public function actionTest()
    {
        $ak = 'Own ak';
        $sk = 'Own sk';
        $domain = 'My address';//View it at https://portal.qiniu.com/bucket/bucket/index page
        $qiniu = new \crazyfd\qiniu\Qiniu($ak, $sk,$domain, 'Create the name of the space','the region';//East China (default), North China, South China, North America
        $key = time();
        $qiniu->uploadFile($_FILES['file']['tmp_name'],$key);
        $url = $qiniu->getLink($key);//Picture URL
        echo $url;
    }

The test can be tested with postman, and the parameter name is file.

The annotations are very clear. If you don’t understand the message or the menu on the left, add me QQ.

Leave a Reply

Your email address will not be published. Required fields are marked *