upload images to cloudinary using php
Hello, I'm using php framework called yii2 to try make the upload to cloudinary servers, but for some reason when I get the file by form field and pass that to:
(new UploadApi())->upload($image);
i get this error:
Cloudinary\Api\Exception\BadRequest
Unsupported source URL: a.jpg
0
-
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 -
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 -
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
Post is closed for comments.
Comments
3 comments