first commit

This commit is contained in:
/usr/bin/nano
2017-04-15 01:34:36 +03:00
commit c715e2a604
5325 changed files with 329700 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
<?php
define('UC_PUBLIC_KEY', 'demopublickey');
define('UC_SECRET_KEY', 'demoprivatekey');

View File

@@ -0,0 +1,225 @@
<?php
/**
* Examples
*/
// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting lib for PHP 5.3/5.4
require_once '../uploadcare/lib/5.3-5.4/Uploadcare.php';
// using namespace
use \Uploadcare;
// create object istance for Api.
$api = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
/**
* Let's start with widgets.
* You can get widget url by using this:
* */
print $api->widget->getScriptSrc()."\n";
/**
* You can just use method below to get all the code to insert widget
*/
print $api->widget->getScriptTag()."\n";
/**
* Ok, lets do some requests. This is request to index (http://api.uploadcare.com).
* This will return an stdClass with information about urls you can request.
*/
$data = $api->request('GET', '/');
/**
* Ok, now lets get file list.
* This request will return stdClass with all files uploaded and some information about files.
* Each files has:
* - size
* - upload_date
* - last_keep_claim
* - on_s3
* - made_public
* - url
* - is_image
* - file_id
* - original_filename
* - removed
* - mime_type
* - original_file_url
*
*/
$files_raw = $api->request('GET', '/files/');
/**
* Previous request is just some raw request and it will return raw data from json.
* There's a better way to handle all the files by using method below.
* It will return an array of \Uploadcare\File objects to work with.
*
* This objects don't provide all the data like in previous request, but provides ways to display the file
* and to use methods such as resize, crop, etc
*/
$files = $api->getFileList();
/**
* getFileList called without any params will return just an array of first 20 files objects (first page).
*
* But you can supply a page you want to see:
*/
$page = 2;
$files = $api->getFileList($page);
/**
* You can get some information about pagination.
*
* You will get an array with params:
* - page: current page
* - next: uri to request next page
* - per_page: number of files per page
* - pages: number of pages
* - previous: uri to request previous page
*
* Use "per_page" and "pages" information to create pagination inside your own project
*/
$pagination_info = $api->getFilePaginationInfo();
/**
* If you have a file_id (for example, it's saved in your database) you can create object for file easily.
* Just user request below
*/
$file_id = '5255b9dd-f790-425e-9fa9-8b49d4e64643';
$file = $api->getFile($file_id);
/**
* Ok, using object of \Uploadcare\File class we can get url for the file
*/
echo $file->getUrl()."\n";
/**
* Or even get an image tag
*/
echo $file->getImgTag('image.jpg', array('alt' => 'Somealt'))."\n";
/**
* Now let's do some crop.
*/
$width = 400;
$height = 400;
$is_center = true;
$fill_color = 'ff0000';
echo $file->crop($width, $height, $is_center, $fill_color)->getUrl()."\n";
/**
* And here's some resize with width and height
* */
echo $file->resize($width, $height)->getUrl()."\n";
/**
* Width only
*/
echo $file->resize($width)->getUrl()."\n";
/**
* Height only
*/
echo $file->resize(false, $height)->getUrl()."\n";
/**
* We can also use scale crop
*/
echo $file->scaleCrop($width, $height, $is_center)->getUrl()."\n";
/**
* And we can apply some effects.
*/
echo $file->effect('flip')->getUrl()."\n";
echo $file->effect('grayscale')->getUrl()."\n";
echo $file->effect('invert')->getUrl()."\n";
echo $file->effect('mirror')->getUrl()."\n";
/**
* We can apply more that one effect!
* */
echo $file->effect('flip')->effect('invert')->getUrl()."\n";
/**
* We can combine operations, not just effects.
*
* Just chain methods and finish but calling "getUrl()".
*
* */
echo $file->resize(false, $height)->crop(100, 100)->effect('flip')->effect('invert')->getUrl()."\n";
/**
* The way you provide operations matters.
* We can see the same operations below, but result will be a little bit different.
*/
echo $file->crop(100, 100)->resize(false, $height)->effect('flip')->effect('invert')->getUrl()."\n";
/**
* You can run any custom operations like this:
*/
echo $file->op('effect/flip')."\n";
echo $file->op('resize/400x400')->op('effect/flip')."\n";
/**
* You can call getUrl with postfix parameter. This is will add some readable postfix.
*/
echo $file->getUrl('image.jpg')."\n";
/**
* You can find more about operations here:
* https://uploadcare.com/documentation/reference/basic/cdn.html
*/
/**
* Ok, it's everything with operations.
* Let's have some fun with uploading files.
* First of all, we can upload file from url. Just use construction below.
* This will return File instance.
*/
$file = $api->uploader->fromUrl('http://www.baysflowers.co.nz/Images/tangerine-delight.jpg');
/**
* File must be uploaded, but it's not stored yet.
* Let's store it.
* We user true flag to be sure that file is uploaded.
**/
try {
$file->store(true);
} catch (Exception $e) {
echo $e->getMessage()."\n";
echo nl2br($e->getTraceAsString())."\n";
}
/**
* We can do any operations with this file now.
**/
echo $file->effect('flip')->getUrl()."\n";
/**
* We can upload file from path
* */
$file = $api->uploader->fromPath(dirname(__FILE__).'/test.jpg');
$file->store();
echo $file->effect('flip')->getUrl()."\n";
/**
* Or even just use a file pointer.
**/
$fp = fopen(dirname(__FILE__).'/test.jpg', 'r');
$file = $api->uploader->fromResource($fp);
$file->store();
echo $file->effect('flip')->getUrl()."\n";
/**
* The last thing you can do is upload a file just from it's contents. But you will have to provide
* mime-type.
*/
$content = "This is some text I want to upload";
$file = $api->uploader->fromContent($content, 'text/plain');
$file->store();
echo $file->getUrl()."\n";
/**
* Lets delete the last file.
*/
$file->delete();

View File

@@ -0,0 +1,221 @@
<?php
// This is just some config with public and secret keys for UC.
require_once 'config.php';
// requesting lib for PHP 5.2
require_once '../uploadcare/lib/5.2/Uploadcare.php';
// using namespace
// create object istance for Api.
$api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
/**
* Let's start with widgets.
* You can get widget url by using this:
* */
print $api->widget->getScriptSrc()."\n";
/**
* You can just use method below to get all the code to insert widget
*/
print $api->widget->getScriptTag()."\n";
/**
* Ok, lets do some requests. This is request to index (http://api.uploadcare.com).
* This will return an stdClass with information about urls you can request.
*/
$data = $api->request('GET', '/');
/**
* Ok, now lets get file list.
* This request will return stdClass with all files uploaded and some information about files.
* Each files has:
* - size
* - upload_date
* - last_keep_claim
* - on_s3
* - made_public
* - url
* - is_image
* - file_id
* - original_filename
* - removed
* - mime_type
* - original_file_url
*
*/
$files_raw = $api->request('GET', '/files/');
/**
* Previous request is just some raw request and it will return raw data from json.
* There's a better way to handle all the files by using method below.
* It will return an array of \Uploadcare\File objects to work with.
*
* This objects don't provide all the data like in previous request, but provides ways to display the file
* and to use methods such as resize, crop, etc
*/
$files = $api->getFileList();
/**
* getFileList called without any params will return just an array of first 20 files objects (first page).
*
* But you can supply a page you want to see:
*/
$page = 2;
$files = $api->getFileList($page);
/**
* You can get some information about pagination.
*
* You will get an array with params:
* - page: current page
* - next: uri to request next page
* - per_page: number of files per page
* - pages: number of pages
* - previous: uri to request previous page
*
* Use "per_page" and "pages" information to create pagination inside your own project
*/
$pagination_info = $api->getFilePaginationInfo();
/**
* If you have a file_id (for example, it's saved in your database) you can create object for file easily.
* Just user request below
*/
$file_id = '5255b9dd-f790-425e-9fa9-8b49d4e64643';
$file = $api->getFile($file_id);
/**
* Ok, using object of \Uploadcare\File class we can get url for the file
*/
echo $file->getUrl()."\n";
/**
* Or even get an image tag
*/
echo $file->getImgTag('image.jpg', array('alt' => 'Somealt'))."\n";
/**
* Now let's do some crop.
*/
$width = 400;
$height = 400;
$is_center = true;
$fill_color = 'ff0000';
echo $file->crop($width, $height, $is_center, $fill_color)->getUrl()."\n";
/**
* And here's some resize with width and height
* */
echo $file->resize($width, $height)->getUrl()."\n";
/**
* Width only
*/
echo $file->resize($width)->getUrl()."\n";
/**
* Height only
*/
echo $file->resize(false, $height)->getUrl()."\n";
/**
* We can also use scale crop
*/
echo $file->scaleCrop($width, $height, $is_center)->getUrl()."\n";
/**
* And we can apply some effects.
*/
echo $file->effect('flip')->getUrl()."\n";
echo $file->effect('grayscale')->getUrl()."\n";
echo $file->effect('invert')->getUrl()."\n";
echo $file->effect('mirror')->getUrl()."\n";
/**
* We can apply more that one effect!
* */
echo $file->effect('flip')->effect('invert')->getUrl()."\n";
/**
* We can combine operations, not just effects.
*
* Just chain methods and finish but calling "getUrl()".
*
* */
echo $file->resize(false, $height)->crop(100, 100)->effect('flip')->effect('invert')->getUrl()."\n";
/**
* The way you provide operations matters.
* We can see the same operations below, but result will be a little bit different.
*/
echo $file->crop(100, 100)->resize(false, $height)->effect('flip')->effect('invert')->getUrl()."\n";
/**
* You can run any custom operations like this:
*/
echo $file->op('effect/flip')."\n";
echo $file->op('resize/400x400')->op('effect/flip')."\n";
/**
* You can call getUrl with postfix parameter. This is will add some readable postfix.
*/
echo $file->getUrl('image.jpg')."\n";
/**
* You can find more about operations here:
* https://uploadcare.com/documentation/reference/basic/cdn.html
*/
/**
* Ok, it's everything with operations.
* Let's have some fun with uploading files.
* First of all, we can upload file from url. Just use construction below.
* This will return File instance.
*/
$file = $api->uploader->fromUrl('http://www.baysflowers.co.nz/Images/tangerine-delight.jpg');
/**
* File must be uploaded, but it's not stored yet.
* Let's store it.
* We user true flag to be sure that file is uploaded.
*/
try {
$file->store(true);
} catch (Exception $e) {
echo $e->getMessage()."\n";
echo nl2br($e->getTraceAsString())."\n";
}
/**
* We can do any operations with this file now.
*/
echo $file->effect('flip')->getUrl()."\n";
/**
* We can upload file from path
* */
$file = $api->uploader->fromPath(dirname(__FILE__).'/test.jpg');
$file->store();
echo $file->effect('flip')->getUrl()."\n";
/**
* Or even just use a file pointer.
*/
$fp = fopen(dirname(__FILE__).'/test.jpg', 'r');
$file = $api->uploader->fromResource($fp);
$file->store();
echo $file->effect('flip')->getUrl()."\n";
/**
* The last thing you can do is upload a file just from it's contents. But you will have to provide
* mime-type.
*/
$content = "This is some text I want to upload";
$file = $api->uploader->fromContent($content, 'text/plain');
$file->store();
echo $file->getUrl()."\n";
/**
* Lets delete the last file.
*/
$file->delete();

View File

@@ -0,0 +1,81 @@
<?php
require_once 'config.php';
require_once '../uploadcare/lib/5.3-5.4/Uploadcare.php';
use \Uploadcare;
$uc_handler = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
?>
<!DOCTYPE html>
<html>
<head>
<meta encoding='utf-8'>
<title>Uploadcare</title>
<link
href="// ucarecdn.com/assets/application-68fbe95c430b7646b16aef33e1ad2824.css"
media="screen" rel="stylesheet" type="text/css" />
<link
href="https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|PT+Sans+Caption&amp;subset=latin,cyrillic"
media="screen" rel="stylesheet" type="text/css" />
<script
src="// ucarecdn.com/assets/application-241564109602bb3ae298c344abff83a7.js"
type="text/javascript"></script>
<?php echo $uc_handler->widget->getScriptTag(); ?>
</head>
<body class='welcome quick_start docs'>
<div class='wrap'>
<header class='header'>
<div class='logo hide-till-loaded'>
<a href="/" class="pic"><img alt="Logo"
src="// ucarecdn.com/assets/logo-07ad940955c42489ffac0a2c2f0c5d62.png" />
</a> <a href="/">Uploadcare</a>
</div>
<div class='logo logo-animated show-till-loaded'>
<a href="/" class="pic"><img alt="Loading"
src="// ucarecdn.com/assets/loading-04f291b2aa39cf277186c36d18d9217f.png" />
</a> <a href="/">Uploadcare</a>
</div>
</header>
<div class='page-content-placeholder'></div>
<div class='page-content'>
<section class='content text-content' style="width: 100%;">
<article class='content-block'>
<ul class="instructions" style="list-style-type: none;">
<li id="step1">
<div class="item-header" role="foldable-folder">
<h2 class="upload">Use Uploadcare widget to upload any image.</h2>
</div>
<div class="hinted">
<form method="POST" action="upload.php" id="uc_form">
<?php echo $uc_handler->widget->getInputTag('qs-file', array('attr' => 1)); ?>
<input type="submit" value="Save!" />
</form>
<p id="uc_form_nofile_hint"
style="display: none; margin-top: 20px; color: #ff0033;">
<img src="img/warning.jpg" alt="" /> Please, upload any image
using Uploadcare widget.
</p>
</div>
</li>
</ul>
</article>
</section>
</div>
</div>
</body>
<script type="text/javascript">
$(function() {
handleUCForm = function() {
if (!$('#uc_form input[name=qs-file]').val()) {
$('#uc_form_nofile_hint').slideDown();
setTimeout('hideNoFileHint()', '1500');
return false;
}
};
hideNoFileHint = function() {
$('#uc_form_nofile_hint').slideUp();
}
$('#uc_form').submit(handleUCForm);
});
</script>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -0,0 +1,71 @@
<?php
require_once 'config.php';
require_once '../uploadcare/lib/5.3-5.4/Uploadcare.php';
use \Uploadcare;
$file_id = $_POST['qs-file'];
$uc_handler = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$file = $uc_handler->getFile($file_id);
try {
$file->store();
} catch (Exception $e) {
echo $e->getMessage()."<br />";
echo nl2br($e->getTraceAsString());
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta encoding='utf-8'>
<title>Uploadcare</title>
<link
href="// ucarecdn.com/assets/application-68fbe95c430b7646b16aef33e1ad2824.css"
media="screen" rel="stylesheet" type="text/css" />
<link
href="https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|PT+Sans+Caption&amp;subset=latin,cyrillic"
media="screen" rel="stylesheet" type="text/css" />
<script
src="// ucarecdn.com/assets/application-241564109602bb3ae298c344abff83a7.js"
type="text/javascript"></script>
</head>
<body class='welcome quick_start docs'>
<div class='wrap'>
<header class='header'>
<div class='logo hide-till-loaded'>
<a href="/" class="pic"><img alt="Logo"
src="// ucarecdn.com/assets/logo-07ad940955c42489ffac0a2c2f0c5d62.png" />
</a> <a href="/">Uploadcare</a>
</div>
<div class='logo logo-animated show-till-loaded'>
<a href="/" class="pic"><img alt="Loading"
src="// ucarecdn.com/assets/loading-04f291b2aa39cf277186c36d18d9217f.png" />
</a> <a href="/">Uploadcare</a>
</div>
</header>
<div class='page-content-placeholder'></div>
<div class='page-content'>
<section class='content text-content' style="width: 100%;">
<article class='content-block'>
<ul class="instructions" style="list-style-type: none;">
<li id="step1">
<div class="item-header" role="foldable-folder">
<h2 class="upload">Here is a cropped image size 400x400. Click
cropped image to see original one.</h2>
<p>
Would you like to <a href="../sample-project">upload more</a>?
</p>
</div>
<div class="hinted">
<a href="<?php echo $file->getUrl(); ?>" target="_blank"><img
src="<?php print $file->resize(400, 400)->getUrl(); ?>" /> </a>
</div>
</li>
</ul>
</article>
</section>
</div>
</div>
</body>
</html>