📜 ⬆️ ⬇️

Screenshots in the clouds

image
Hello!

Many of us sometimes need to share our screenshots, and instead of sending a screenshot file by email / skype, we can use third-party services, of which there are many, and store photos there.

But, thanks to ayurganov , we can set up a simple Gyazo service on our hosting with the help of the article http://habrahabr.ru/blogs/soft/132937/
')
I went further and developed the theme by the fact that my screenshots are stored on RackSpace CloudFiles - CDN from RackSpace, which can withstand any “habraeffect”. A link to the files beautifully shorts through Bit.ly.


To use this script you need to have:
  1. Create a RackSpace container and allow it to share files on CDN:
    image
  2. In the settings of the RackSpace account we find our API key.
  3. In the bitly account, in the settings, we enable the use of the API and in the same place we find the username and password.
  4. On the host copy the contents of the repository
  5. According to the article http://habrahabr.ru/blogs/soft/132937/ we set up a client.

The main application code looks like this:
<?php require('files/cloudfiles.php'); //Bitly credentials $bitly_name='##Bitly_name'; $bitly_key='##Bitly_key'; $gyazo_url = $_SERVER['SERVER_NAME']; $company_name='my_company'; //Rackspace Credentials $username='##Rackspace_UN'; $key='##Rackspace_key'; $container='##Rackspace_container'; /* returns the shortened url */ function get_bitly_short_url($url,$login,$appkey,$format='txt') { $connectURL = 'http://api.bit.ly/v3/shorten/?login='.$login.'&apiKey='.$appkey.'&uri='.urlencode($url).'&format='.$format; return curl_get_result($connectURL); } /* returns a result form url */ function curl_get_result($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } //When file is uploaded if(isset($_FILES['imagedata']['name'])) { $name = substr(md5(time()), -28).'.'.$company_name.'.png'; //Store it on Rackspace if ($tempname = $_FILES['imagedata']['tmp_name']){ $auth = new CF_Authentication($username, $key); $auth->authenticate(); $conn = new CF_Connection($auth); $container = $conn->create_container($container); $object = $container->create_object($name); $object->load_from_filename($tempname); $fileuri = $container->make_public(); $imageu = $object->public_uri(); //Output file url echo $gyazo_url."?limage=$imageu"; } }else { $limage=$_GET['limage']; $shorten = get_bitly_short_url($limage,$bitly_name,$bitly_key); echo "<head> <link rel='shortcut icon' href=$limage> </head> <style type='text/css'> #url1, #url2 { width:150px; } #url2 { } .copy { display:inline-block; height:16px; width:16px; background:url(files/copy.png); position:relative; top:3px; } .copy:hover { opacity:0.5; cursor:pointer; } .copied { display:inline-block; height:16px; width:16px; background:url(files/copied.png); position:relative; top:3px; margin-left:5px; } .wrap { display:block; width:300px; } </style> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> <script src='files/jquery.zclip.min.js'></script> <script type='text/javascript'> $(document).ready(function(){ $('#copy1').zclip({ path:'files/ZeroClipboard.swf', copy:$('#url1').val(), afterCopy:function(){ $(this).after('<span class=copied></span>'); $(this).next('.copied').fadeOut('slow'); }, }); $('#copy2').zclip({ path:'files/ZeroClipboard.swf', copy:$('#url2').val(), afterCopy:function(){ $(this).after('<span class=copied></span>'); $(this).next('.copied').fadeOut('slow'); }, }); $('#url1, #url2').click(function(){ $(this).select(); }); }); </script> <span class='wrap'><input id='url1' type='text' value=$shorten> <span class='copy' id='copy1'></span></span> <hr /> <img src=$limage>"; } ?> 


In the browser, the screenshots will look like this:
image

And clicking on the button near the link, the flash drive will copy it to the clipboard. Further, this link can be easily transferred to whom you need, inserted into a habrahabr or djira.

All in all, very comfortable! Recommend!

Shl. Do not be intimidated by my shortbridge qblx.co - this is the same bit.ly, only with a personal domain.

UPDATE: Gyazo server for Amazon S3 is here: Github.com

Source: https://habr.com/ru/post/138858/


All Articles