Exemple #1
0
 /**
  * Upload file from string using mime-type.
  *
  * @param string $content
  * @param string $mime_type
  * @return Uploadcare_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 Uploadcare_File($file_id, $this->api);
 }
Exemple #2
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;
 }
Exemple #3
0
 /**
  * Is public key valid?
  */
 public function testPublicKeyValid()
 {
     $api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
     $this->assertTrue($api->getPublicKey() == 'demopublickey', 'This is true');
 }