upload images to cloudinary using php

Comments

3 comments

  • Avatar
    Eme Marketing

    only way to make it work is to place the relative path, did u know a better way to import files?

    (new UploadApi())->upload('/path/to/file.png');

    0
    Comment actions Permalink
  • Avatar
    Eme Marketing

    ok i found the soluction.

    ```

        public function actionCreate()
        {
            $model = new Galerias();
    
            // inicializar o cloudinary
            $config = Configuration::instance();
            $config->cloud->cloudName = 'cloudName';
            $config->cloud->apiKey = 'yayaiknow';
            $config->cloud->apiSecret = 'gogogodude';
            $config->url->secure = true;
    
            // esta a ser feito o upload
            if ($model->load(Yii::$app->request->post())) {
                $data2 = date('Y-m-d h:m:s');
                if($model->validate()) {
                    $image = UploadedFile::getInstance($model, 'image');
                    // maybe remove this if to get URL of image from callback
                    if((new UploadApi())->upload($image->tempName)){
                        $data = date('Y-m-d h:m:s');
                        $model->created_at = $data;
                        $model->updated_at = null;
                        if($model->save()){
                            return $this->redirect(['view', 'id' => $model->id]);
                        }
                    }
                }
            }
    
            return $this->render('create', [
                'model' => $model,
            ]);
    
        }```
    0
    Comment actions Permalink
  • Avatar
    Francis Tagbo

    Hi,

    Glad you found a solution!

    If you have any further questions, you can comment here or you can create a support ticket thru:

    https://support.cloudinary.com/hc/en-us/requests/new

    Regards,

    Francis

    0
    Comment actions Permalink

Please sign in to leave a comment.