示例#1
0
    /**
     * Returns <script> sections to include Uploadcare widget
     *
     * @param string $version Uploadcare version
     * @param bool $async
     * @return string
     */
    public function getScriptTag($version = null, $async = false)
    {
        $async_attr = $async ? 'async="true"' : '';
        $result = <<<EOT
<script>UPLOADCARE_PUBLIC_KEY = "{$this->api->getPublicKey()}";</script>
<script {$async_attr} src="{$this->getScriptSrc($version)}" charset="UTF-8"></script>
EOT;
        return $result;
    }
示例#2
0
 /**
  * Create group from array of File objects
  *
  * @param array $files
  * @return Group
  */
 public function createGroup($files)
 {
     $data = array('pub_key' => $this->api->getPublicKey());
     foreach ($files as $i => $file) {
         $data["files[{$i}]"] = $file->getUuid();
     }
     $ch = $this->__initRequest('group');
     $this->__setRequestType($ch);
     $this->__setData($ch, $data);
     $this->__setHeaders($ch);
     $resp = $this->__runRequest($ch);
     $group = $this->api->getGroup($resp->id);
     return $group;
 }
示例#3
0
 /**
  * Upload file from string using mime-type.
  *
  * @param string $content
  * @param string $mime_type
  * @return File
  */
 public function fromContent($content, $mime_type)
 {
     $tmpfile = tempnam(sys_get_temp_dir(), 'ucr');
     $temp = fopen($tmpfile, 'w');
     fwrite($temp, $content);
     fclose($temp);
     $data = array('UPLOADCARE_PUB_KEY' => $this->api->getPublicKey(), 'file' => sprintf('@%s;type=%s', $tmpfile, $mime_type));
     $ch = $this->__initRequest('base');
     $this->__setRequestType($ch);
     $this->__setData($ch, $data);
     $this->__setHeaders($ch);
     $data = $this->__runRequest($ch);
     $file_id = $data->file;
     return new File($file_id, $this->api);
 }
示例#4
0
 /**
  * Upload file from local path.
  *
  * @param string $path
  * @param string $mime_type
  * @return File
  */
 public function fromPath($path, $mime_type = false)
 {
     if (function_exists('curl_file_create')) {
         if ($mime_type) {
             $f = curl_file_create($path, $mime_type);
         } else {
             $f = curl_file_create($path);
         }
     } else {
         if ($mime_type) {
             $f = '@' . $path . ';type=' . $mime_type;
         } else {
             $f = '@' . $path;
         }
     }
     $data = array('UPLOADCARE_PUB_KEY' => $this->api->getPublicKey(), 'file' => $f);
     $ch = $this->__initRequest('base');
     $this->__setRequestType($ch);
     $this->__setData($ch, $data);
     $this->__setHeaders($ch);
     $data = $this->__runRequest($ch);
     $file_id = $data->file;
     return new File($file_id, $this->api);
 }
示例#5
0
 /**
  * Returns <script> sections to include Uploadcare widget
  *
  * @param string $version Uploadcare version
  * @return string
  */
 public function getScriptTag($version = null)
 {
     $result = sprintf('<script>UPLOADCARE_PUBLIC_KEY = "%s";</script>', $this->api->getPublicKey());
     $result .= sprintf('<script async="async" src="%s"></script>', $this->getScriptSrc($version));
     return $result;
 }