Monday, 29 February 2016

Creating app with Flickr API in PHP
Using Flickr API you can retrieve plethora of photographs and in turn may create awesome applications. Moreover, you may upload your application to Flickr's marketplace APP Garden and make bucks and recognition too.
In this tutorial we will see how to get started with Flickr API. We will create simple application using Flickr API and in the course we learn some nuances of how to unleash the potential of Flickr's awesome photo sharing services.
Time for some code now. As you have a URL which may return data of your demand, in JSON format here, you have to use a programming language to decode that JSON data and present that to the user. 'https://www.flickr.com/services/api/' page provides you with a list of programming language usage under 'API Kits' section. For this application we will use Jquery to decode the JSON data returned and then append that to the HTML page. We will also collect the size of the photos user want those to be displayed.
So, we have three steps to go. First we have to decode JSON data returned by 'flickr.photos.getRecent' method. Second we have to collect data from browser supplied by user to filter the available photos according to the size user want to see and then display only photos with that size. The code for the job is given below. Download the code, replace the api_key with yours, and play around.
view plaincopy to clipboardprint?
In this tutorial we will see how to get started with Flickr API. We will create simple application using Flickr API and in the course we learn some nuances of how to unleash the potential of Flickr's awesome photo sharing services.
Time for some code now. As you have a URL which may return data of your demand, in JSON format here, you have to use a programming language to decode that JSON data and present that to the user. 'https://www.flickr.com/services/api/' page provides you with a list of programming language usage under 'API Kits' section. For this application we will use Jquery to decode the JSON data returned and then append that to the HTML page. We will also collect the size of the photos user want those to be displayed.
So, we have three steps to go. First we have to decode JSON data returned by 'flickr.photos.getRecent' method. Second we have to collect data from browser supplied by user to filter the available photos according to the size user want to see and then display only photos with that size. The code for the job is given below. Download the code, replace the api_key with yours, and play around.
view plaincopy to clipboardprint?
<html>
<head>
<title>Creating app with Flickr API</title>
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style type="text/css">
#sq,#lg-sq,#thumb,#small,#mid,#ori {
width: 100%
}
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var apiurl,myresult,apiurl_size,selected_size;
apiurl = "https://api.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=ca370d51a054836007519a00ff4ce59e&per_page=10&format=json&nojsoncallback=1";
$(document).ready(function(){
$("#sq").click(function(){
selected_size=75;
})
});
$(document).ready(function(){
$("#lg-sq").click(function(){
selected_size=150;
})
});
$(document).ready(function(){
$("#thumb").click(function(){
selected_size=100;
})
});
$(document).ready(function(){
$("#small").click(function(){
selected_size=240;
})
});
$(document).ready(function(){
$("#mid").click(function(){
selected_size=500;
})
});
$(document).ready(function(){
$("#ori").click(function(){
selected_size=640;
})
});
$(document).ready(function(){
$('#button').click(function(){
$.getJSON(apiurl,function(json){
$.each(json.photos.photo,function(i,myresult){
apiurl_size = "https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=ca370d51a054836007519a00ff4ce59e&photo_id="+myresult.id+"&format=json&nojsoncallback=1";
$.getJSON(apiurl_size,function(size){
$.each(size.sizes.size,function(i,myresult_size){
if(myresult_size.width==selected_size){
$("#results").append('<p><a href="'+myresult_size.url+'" target="_blank"><img src="'+myresult_size.source+'"/></a></p>');
}
})
})
});
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Select size of photos (in pixels) you want them to be displayed</h2>
</div>
</div>
<div class="row">
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="sq">Square [75X75]</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="lg-sq">Large Square [150X150]</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="thumb">Thumbnail</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="small">Small</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="mid">Medium</button>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary" id="ori">Original</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h2>Hit This button to fetch photos</h2>
<button type="button" class="btn btn-success" id="button">Fetch Recent Photos</button>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="results"></div>
</div>
</div>
</div>
</body>
</html>

Soundcloud MP3 Search using PHP & jQuery Ajax
Instant Search is one of the most popular term in the internet search, that shows you results as you type. I found that there are no more articles on Searching Souncloud Audios using PHP in the internet.
So In this tutorial, I will tell you how to search audios in Soundcloud database using PHP & jQuery Ajax
SoundCloud is an online audio distribution platform based in Berlin, Germany that enables its users to upload, record, promote and share their originally-created sounds.
Step 1
We need client Id from soundcloud app to access their audios via API
So we need to Register our app in Soundcloud from here – http://soundcloud.com/you/apps/new
Please refer the screenshot below
Step 2
After getting your Client Id, Pass it to url & access the datas from soundcloud database. The result should be in JSON format.
By using json_decode function, it decodes the JSON string. By passing TRUE as second parameter, It convert json objects into associative arrays.
After converting the JSON objects into associative arrays, we can easily get the required datas using foreach as shown below
Step 3
Below jQuery code is used to call the php file to access soundcloud audios using their API
I have used ClearTimeOut & SetTimeout javascript function to delay the Ajax call to avoid unwanted search requests to Soundcloud Database API
Soundcloud JSON file format
I hope you love this tutorial :)
Please don’t forget to share and subscribe to latest updates of the blog. Thanks!
Download
So In this tutorial, I will tell you how to search audios in Soundcloud database using PHP & jQuery Ajax
SoundCloud is an online audio distribution platform based in Berlin, Germany that enables its users to upload, record, promote and share their originally-created sounds.
Step 1
We need client Id from soundcloud app to access their audios via API
So we need to Register our app in Soundcloud from here – http://soundcloud.com/you/apps/new
Please refer the screenshot below
Step 2
After getting your Client Id, Pass it to url & access the datas from soundcloud database. The result should be in JSON format.
By using json_decode function, it decodes the JSON string. By passing TRUE as second parameter, It convert json objects into associative arrays.
$api_url = 'http://api.soundcloud.com/tracks.json?client_id=your_client_id&q='.urlencode($key);
//get json datas from soundcloud API
$api_content = file_get_contents($api_url);
//Decodes a JSON string
$api_content_array = json_decode($api_content, true);
After converting the JSON objects into associative arrays, we can easily get the required datas using foreach as shown below
foreach ($api_content_array as $val) { ?>
<div class="videos" id="sc-<?php echo $val['id'];?>">
<div class="expand-video"> <a class="soundcloud" id="<?php echo $val['id'];?>" href="<?php echo $val['uri'];?>"><span></span> <img src="<?php echo $val['user']['avatar_url'];?>" width="120" height="90" title="Play" alt="Play"/> </a> </div>
<div class="details">
<h6><?php echo $val['title'];?></h6>
<p class="link"><?php echo $val['user']['username'];?></p>
<p class="desc"><?php echo $val['description'];?></p>
</div>
</div>
<?php
}
?>
Step 3
Below jQuery code is used to call the php file to access soundcloud audios using their API
I have used ClearTimeOut & SetTimeout javascript function to delay the Ajax call to avoid unwanted search requests to Soundcloud Database API
var timer = null;
jQuery("#keyword").keyup(function() {
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {
var sc_keyword = jQuery("#keyword").val();
var obj = jQuery(this);
if(sc_keyword != '') {
jQuery(".ajax_indi").show();
var str = jQuery("#fb_expand").serialize();
jQuery.ajax({
type: "POST",
url: "fetch_soundcloud.php",
data: str,
cache: false,
success: function(htmlresp){
jQuery('#results').html(htmlresp);
jQuery(".ajax_indi").hide();
}
});
} else {
alert("Search for your favourite musics");
jQuery("#keyword").focus();
}
}, 500);
});
Soundcloud JSON file format
[ { "artwork_url" : "https://i1.sndcdn.com/artworks-000054792391-28glcc-large.jpg?86347b7",
"attachments_uri" : "https://api.soundcloud.com/tracks/104496032/attachments",
"bpm" : null,
"comment_count" : 219,
"commentable" : true,
"created_at" : "2013/08/08 03:58:34 +0000",
"description" : "Like us our fan page for more Songs https://www.facebook.com/BollywoodLatestSong\r\nSingers: Chinmayi Sripaada, Gopi Sunder\r\nMusic: Vishal-Shekhar\r\nLyricist: Amitabh Bhattacharya\r\nTamil Poetry: Saint Thiruppaan Alvar (8th Century A.D)\r\nCast: Shahrukh Khan, Deepika Padukone\r\nMusic on: T-Series",
"download_count" : 0,
"downloadable" : false,
"duration" : 350987,
"embeddable_by" : "all",
"favoritings_count" : 3850,
"genre" : "bollywood songs",
"id" : 104496032,
"isrc" : "",
"key_signature" : "",
"kind" : "track",
"label_id" : null,
"label_name" : "",
"last_modified" : "2014/07/15 02:21:14 +0000",
"license" : "all-rights-reserved",
"original_content_size" : 10136447,
"original_format" : "mp3",
"permalink" : "titli-chennai-express",
"permalink_url" : "http://soundcloud.com/chennai-express/titli-chennai-express",
"playback_count" : 282240,
"policy" : "ALLOW",
"purchase_title" : null,
"purchase_url" : null,
"release" : "",
"release_day" : null,
"release_month" : null,
"release_year" : null,
"sharing" : "public",
"state" : "finished",
"stream_url" : "https://api.soundcloud.com/tracks/104496032/stream",
"streamable" : true,
"tag_list" : "\"chennai express\"",
"title" : "Titli - Chennai Express - Chennai Express",
"track_type" : "",
"uri" : "https://api.soundcloud.com/tracks/104496032",
"user" : { "avatar_url" : "https://i1.sndcdn.com/avatars-000075788600-y2acsy-large.jpg?86347b7",
"id" : 53653218,
"kind" : "user",
"last_modified" : "2014/08/07 15:46:22 +0000",
"permalink" : "chennai-express",
"permalink_url" : "http://soundcloud.com/chennai-express",
"uri" : "https://api.soundcloud.com/users/53653218",
"username" : "Chennai Express"
},
"user_id" : 53653218,
"video_url" : null,
"waveform_url" : "https://w1.sndcdn.com/X8M7SRav3Iq3_m.png"
}
]
I hope you love this tutorial :)
Please don’t forget to share and subscribe to latest updates of the blog. Thanks!
Download
Thursday, 25 February 2016

Create Wifi HotSpot Using CMD
Hello friends !!! Have you ever thought using your pc's Fast Internet connection onto your phone or making it share-able to use on other computers. WIFI hot spot is the method that allows you to do so. There are many software's which allows you to create hot spot on computer but they are either costly or vulnerable to computer security(they may contain viruses or malwares) .In this post i am going to explain the simplest possible way to create WiFi hot spot on computer.
Step 1 : Hit "Win key + R" or goto start menu and select "RUN" . In Run box type "Notepad".
Step 2 : Open Notepad, copy and paste below code into it.
Step 3 : Save this file as hotspot.bat Make sure you have given the extension as ".bat"
Step 4 : Create another notepad file and paste the below code into it.
So from now when ever you want to start the Wi-Fi Hotspot, simply right click the hotspot.bat file and run it as administration, your Wi-Fi hotspot will start to broadcast.
As soon as you are done you can double click the StopWifi.bat file and your broadcast will be stopped.
Step 1 : Hit "Win key + R" or goto start menu and select "RUN" . In Run box type "Notepad".
Step 2 : Open Notepad, copy and paste below code into it.
netsh wlan set hostednetwork mode=allow ssid=HOTSPOTNAME key=PASSWORD
netsh wlan start hostednetwork
- Change the SSID value colored with red with the name of your hotspot.
- Change the key value colored with red security code required to authenticate users.
Step 3 : Save this file as hotspot.bat Make sure you have given the extension as ".bat"
Step 4 : Create another notepad file and paste the below code into it.
netsh wlan stop hostednetworkSave this file as stopwifi.bat This file is to stop our Wi-Fi Hotspot.
So from now when ever you want to start the Wi-Fi Hotspot, simply right click the hotspot.bat file and run it as administration, your Wi-Fi hotspot will start to broadcast.
As soon as you are done you can double click the StopWifi.bat file and your broadcast will be stopped.

Upload File with FTP using PHP
FTP is one of the most useful tool or protocol for all web developers or designers. We can move files from one server to another with FTP tools very easily. PHP provides build in support for FTP protocol. That’s why we can work with FTP very easily using some FTP functions. In this post I’m going to show how to upload or put file to a server using PHP functions.
<?php
$host = "localhost";
$username = "username";
$password = "password";
$local_file = 'path/to/file.txt';
$remote_file = 'public_html/file.txt';
#Connecting to FTP Server:
$con = ftp_connect($host, 21) or die("Could not connect to FTP server");
#Login to FTP Server:
$log = ftp_login($con, $username, $password) or die("Fail to longin");
#Uploading File:
$upload = ftp_put($con, $remote_file, $local_file, FTP_ASCII);
if($upload) echo 'Success!';
#Closing Connection:
ftp_close($con);
?>

Create ZIP File with PHP using ZipArchive
Creating zip file using PHP is very easy. To do this you need to write couple of lines code. In this post I am going to show you how to create simple zip file using PHP. For do this I am using ZipArchive class. If your system dose not have support for this class you can download and install it from here.
<?php
// Files in array
$files = array('one.jpg', 'two.png', 'three.gif');
// Zip file name
$zipname = 'my.zip';
$zip = new ZipArchive;
//Creating zip file
$zip->open($zipname, ZIPARCHIVE::CREATE);
foreach ($files as $file) {
//Adding files into zip
$zip->addFile($file, basename($file));
}
$zip->close(); //Closing file
?>

Get Remote File Size Using PHP
We can get a file's size by using PHP build in filesize function. But the problem is this function only works for local file. If you want to get a remote file's size you need to think some other way. In this post I am going to show you how we can get a remote file's size from it's header information with out downloading file. I will show you two example. One, using get_headers function and another using cURL. Using get_headers is very simple approach and works for every body. Using cURL is more advance and powerful. You can use any one of these. But I recommend to use cURL approach. Here we go..
get_headers Approach:
Output:
cURL Approach:
Output:
get_headers Approach:
<?php
/**
* Get Remote File Size
*
* @param sting $url as remote file URL
* @return int as file size in byte
*/
function remote_file_size($url){
# Get all header information
$data = get_headers($url, true);
# Look up validity
if (isset($data['Content-Length']))
# Return file size
return (int) $data['Content-Length'];
}
echo remote_file_size('http://www.google.com/images/srpr/logo4w.png');
?>
Output:
19978
cURL Approach:
<?php
/**
* Remote File Size Using cURL
* @param srting $url
* @return int || void
*/
function remotefileSize($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_exec($ch);
$filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
if ($filesize) return $filesize;
}
echo remotefileSize('http://www.google.com/images/srpr/logo4w.png');
?>
Output:
19978

Download File from Remote Server with PHP
On my previous post I was shown how we can get a remote file size without download it in php. Today I am going to show you how can we download a file from remote server with php.
There are many ways in PHP to download file from remote server. We can use php functions like copy, file_get_content, fopen, fsockopen to download remote files. These functions are well but today we will use curl to download file. Because it the advanced way to working with remote resources.We can download large file with minimum memory usages in this way.
getHeaders Function
This function gets all header information before downloading a file. This function will help you to know file is exist or not and filesize
download Function
This function download file form remote server.
Usages
There are many ways in PHP to download file from remote server. We can use php functions like copy, file_get_content, fopen, fsockopen to download remote files. These functions are well but today we will use curl to download file. Because it the advanced way to working with remote resources.We can download large file with minimum memory usages in this way.
getHeaders Function
This function gets all header information before downloading a file. This function will help you to know file is exist or not and filesize
/**
* Get Headers function
* @param str #url
* @return array
*/
function getHeaders($url)
{
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 3 );
curl_exec( $ch );
$headers = curl_getinfo( $ch );
curl_close( $ch );
return $headers;
}
download Function
This function download file form remote server.
/**
* Download
* @param str $url, $path
* @return bool || void
*/
function download($url, $path)
{
# open file to write
$fp = fopen ($path, 'w+');
# start curl
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
# set return transfer to false
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
# increase timeout to download big file
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
# write data to local file
curl_setopt( $ch, CURLOPT_FILE, $fp );
# execute curl
curl_exec( $ch );
# close curl
curl_close( $ch );
# close local file
fclose( $fp );
if (filesize($path) > 0) return true;
}
Usages
$url = 'http://path/to/remote/file.jpg';
$path = 'uploads/file.jpg';
$headers = getHeaders($url);
if ($headers['http_code'] === 200 and $headers['download_content_length'] < 1024*1024) {
if (download($url, $path)){
echo 'Download complete!';
}
}
Subscribe to:
Posts
(
Atom
)