GithubHelp home page GithubHelp logo

uploadcare-yii's Introduction

Uploadcare Yii Framework Extension

This is an extension for Yii Framework to work with Uploadcare

It's based on a uploadcare-php library.

Requirements

  • Yii 1.1+
  • PHP 5.2+
  • php-curl

Install

Clone extension from git to your extension directory:

git clone git://github.com/uploadcare/uploadcare-yii.git extension/uploadcare --recursive

Edit your config/main.php to like like this:

Yii::app()->params->uploadcare = array(
    'public_key' => 'demopublickey',
    'secret_key' => 'demoprivatekey',
);

return array(
  'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
  'name'=>'Yii Framework: Uploadcare Demo',
  'import' => array(
      'application.extensions.uploadcare.CUploadcare',
  ),    
);

Now you can access object of class Uploadcare_Api like this:

CUploadcare::api()

Usage

Create a controller:

class SiteController extends CController
{ 
  /**
   * This is the default action that displays the phonebook Flex client.
   */
  public function actionIndex()
  {
    if (isset($_POST['file_id'])) {
      $file_id = $_POST['file_id'];
      $file = CUploadcare::api()->getFile($file_id);
      $file->store();
    }
    $this->render('index', array('file' => $file));
  }
}

Inside your view you can initialize Uploadcare widget. This will show a <script> section:

<?php echo CUploadcare::api()->widget->getScriptTag(); ?>

Display form:

<?php echo CHtml::beginForm(); ?>
<div class="row">
  <?php echo CHtml::hiddenField('file_id', '', array('role' => 'uploadcare-uploader')); ?>
</div>
<div class="row submit">
  <?php echo CHtml::submitButton('Go!'); ?>
</div>
<?php echo CHtml::endForm(); ?>

Don't forget to provide "array('role' => 'uploadcare-uploader')" so widget will display properly.

You should see a from with Uploadcare widget. Upload a file a press "Go!".

This code inside a controller will store a file and it will be available at CDN:

if (isset($_POST['file_id'])) {
  $file_id = $_POST['file_id'];
  $file = CUploadcare::api()->getFile($file_id);
  $file->store();
}

You can use "$file" inside your view to display file and call different operations:

<?php echo $file->scaleCrop(300, 300, true)->getImgTag(); ?>

You can find out more about CDN and operations here

uploadcare-yii's People

Contributors

grayhound avatar v-atamanenko avatar dmitry-mukhin avatar

Watchers

Oleg Sharov avatar Roman Sedykh avatar Adam Engebretson avatar James Cloos avatar  avatar  avatar Arsenii avatar Siarhei Bautrukevich avatar Alexander Perlamutrov avatar Dmitry Petrov avatar Nikolay avatar Anastasia Kataeva avatar Filippov Andrey avatar Alex Chernenko avatar Arch avatar Alex Sova avatar  avatar

uploadcare-yii's Issues

CURL SSL CA error

I need add this

__setHeaders () {
......
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

to Api.php and Uploader.php
Else I have arror from Curl.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.