RSSArchive for June, 2015

Introducing Amazon ECHO !

After seven months of rigorous tests on an invitation only basis, the Amazon Echo is finally available for everyone to buy. It is a part wireless personal assistant speaker which can be integrated with the different smart home devices. Amazon Echo , selling for $179 (roughly Rs. 11,390), is a voice-activated device which can “fetch” music or news along with controlling the home automation such as lighting and temperature and is available for buyers around the world at a price of one hundred seventy nine US dollars. In India it is priced at eleven thousand three hundred ninety.  Customers have been waiting for it and their response to the Amazon Echo has been very positive hence Amazon is trying really hard to
build more as quickly as possible in order to meet the growing demands.  Amazon’s vice president says that they are very grateful to the early birds (customers) and appreciates their engagement along with providing valuable feedback which has helped evolve the gadget. The Echo now features audio books, Pandora, home automation, sports scores, calendar, and much more.

amazon-echo-introduction

The device is cylindrical in shape and has a cloud based brain referred to as Alexa which are built into its speakers and can be seen as a challenge to virtual assistants in Apple’s coveted mobile devices known as Siri. Echo speakers are a ring of microphones built into a can shape which enables the device to identify different voices even when music is playing. News, weather, streaming music and much more can be accessed by Echo using wireless Internet connections. A feature that makes Echo appealing is the fact that it can also be managed remotely using free applications built for smartphones which are powered by Apple, Android or Amazon’s Fire operating software.

Amazon would keep testing the Echo and gauge on early reviews since its likely that they had a slow rollout. Hence the company would not encourage a demand it couldn’t meet. Echo was previously priced at one hundred ninety nine US dollars for non Amazon Prime members but the company made it very clear that the early pricing would only be available for a limited time. Echo is the perfect example for how a smart home should feel like. It’s unclear if the consumers will pay for the funky system but the Echo does have potential especially when it comes to shopping and smart home capabilities. Amazon is in the business of selling things and the fact that Echo makes it easier to buy items makes it a natural fit in the market. The Echo if continues to move into the territory of smart home automation like Google or Apple have done recently then it is also an obvious choice to become Amazon’s smart home-automation hub. Amazon announced in April that the Amazon Echo could work with WeMo and Philips Hue’s smart lights and switches allowing users to adjust the lights in their home via voice control.

With so much on offer in the market with varied features and deals it is not easy to say whether consumers will automatically flock to the Amazon Echo. Nowadays a big challenge in the smart home industry is to show people why they would even need something like this and why it’s worth their time and money. As of now Amazon hasn’t reported any sales of the Echo during its release but the company has fallen on both sides of the success spectrum for its hardware in the past with the Kindle having solid interest early on but the Fire phone becoming a massive flop. So be ready for a whole new expereince.

A Real Time SOS Alert System For A Secure Ride : UBER

Recently, Uber has publicized the prologue of a ‘Dynamic & Integrated SOS Revise Solution for Law Enforcement’, which assures a superior, strong and incorporated security system for riders, especially women.

Uber’s India Safety Lead, Deval Delivala, said, “We welcome the prospect to collaborate with more police departments around the nation to make sure your safety, and support law enforcement agencies to clinch onto new technology and get better liability and traceability in inner-city mobility.”

uber-sos-image

How Will It Work ?

In February 2015, Uber had introduced a sequence of safety measures to make sure that their customers are secure during a ride. SOS feature was element of this novel stratagem.

From now, wherever or whenever an Uber rider will press that SOS button:

The rider would be capable to unite with the police through a call, without delay. A real time ‘SOS alert’ is produced, which is delivered to the nearby police control room at once. This SOS Alert will enclose the precise vehicle spot, tracked by a GPS which is anticipated on safety devices watched at the police control room. This will facilitate the law enforcement agencies to take action quickly and accurately during any real-time issue.

UBER SOS Alert

Captivatingly, Uber has installed such monitoring devices at all major police control rooms, at their personal expenditure. Deval further said, “Yes, we’ve voluntarily paid for the equipments and have  installed at all major police control rooms across the nation.”

Uber & The Matter of Safety

Previous year, the online taxi service business in India was flustered after an occurrence of rape that happened in a Uber cab. There was a gigantic public anger over this event, which provoked the Govt. to straight away ban all such apps such as TaxiForSure, Ola and prominetely Uber. Though Uber re-entered the market with a broadcasting taxi license in the month of January this year, Delhi Transport Department (DTD) discarded their license, and the issue of survival emerged large over them. If truth be told, Govt. even considered about barring their IP address to discontinue people from exercising their apps and to travel through those cabs.

After the all-purpose govt budget, Uber and other taxi aggregators were incorporated in the service tax group, which aided them to make lawful standing. They straight away increased their fares after addition of this service tax, and at present as they are paying taxes and familiar as a radio taxi aggregator, their business is functioning without any difficulties.

When questioned about these sorts of partnerships, the past Commissioner of Police, Delhi, BK Gupta, proclaimed “It is significant that business and law enforcement take a strapping collaborative loom towards guaranteeing passenger protection. Uber’s pains to this matter are highly praiseworthy; their technology resolutions which bring unparalleled simplicity, traceability and responsibility are making riding around cities safer. Partnerships like such, where all stakeholders work jointly as a squad with the preeminent interests of the community at core, will go an extensive way in making India secure.”

This superior tech promotion to the accessible SOS feature facilitates the authorities to take action within moments of being alerted in the rare occasion of an emergency, and some times, a few seconds make the real difference. With the help of this technology way out, local authorities will be able to keep a track every SOS alert sent by an Uber ride real-time within their city.

The San Francisco-based company Uber at present operates in around 11 Indian cities such as Mumbai and Delhi, but Deval is reserved about which cities this feature will be accessible in.

Facebook gets ‘Save’ element – The Eventual Bookmarker ?

We all are aware that Facebook is the biggest community on Earth – if Facebook had to be a country, then by now it would have been almost equal or may have even surpassed the population of China. So, noticeably when Facebook launches any new-fangled feature, it has likely that it will be utilized by more than a million people, and that is quite noteworthy.

Presently, Facebook has introduced a new characteristic called –‘Save on Facebook’, which may well be a strapping challenger to a well-liked ‘save and read it later on” mobile app pouch.

If you are a tech-savvy person, you might recollect well that Facebook had obtained a ‘read-it-later’ service called SPOOL roughly 2 years back. It seems like Facebook has at last employed Spool’s technology and incorporated it with their cell phone app. Let us have a glance at this feature in little more specification.

facebook-save-posts

How does Facebook Save and bookmark ?

It is rather simple actually – Everything that you are coming across on your Facebook timeline is capable of being saved for accessing it at any date. Plus, this feature is clearly very supportive to nearly everybody as every time you fall across something helpful, you might not have time to discover or learn/read completely. During such situation, Facebook user can purely save it and read it at spare time and gain the missed out information.

The best part about the bookmark is that it can Save not only posts but also a wide number of places, links, videos, movies, TV or music.

Once the user has saved a particular item, it is only noticeable to them, on the other hand, if they desire they can also prefer to share it with their family and friends on their FB timeline.

Moreover, user’s saved topics are structured by category and they can swipe right on every article in order to share it with your friends or into your library list. Facebook has in addition added further a knick-knack reminder feature that will send you timely reminders of bookmarked items in their news feed time and again.

As per Facebook update, Save will be obtainable to everybody on Android, iOS and the web in forthcoming days.

Is there Threat to ‘Pocket’ ?

The question will apparently be raised out if prologue of this fresh feature by Facebook will be menace to bookmarking apps such as Pocket.

When gigantic online rulers like Facebook and Google initiated a new feature, it is definitely going to have an effect on companies that provide alike services. Worst, smaller players might even stop to exist. Nonetheless, when the question is on Pocket, they have time-honored user base and proffer far too many features in comparison to ‘Facebook Save’.

What has to be observed is how Facebook’s Save service progress. In current figure, it may not be a key threat.

About Facebook Bookmarking

Have you ever come across a great Facebook post that you wished to bookmark and save for later reading? There are actually two style to do it, and yes both of them are simple. Here are the 2 steps:

First, find the Facebook post you want to bookmark for later reading and save, then get on on the link that tells you the day and time it had been shared. You’ll get it just underneath the name of the individual or page who posted it.

Second, once you click on the day and time link, you’ll be brought to a new page that shows up just that post and all the comments people have put on it. Here, you’ll see the post URL at the top side. All you require to do now is add it to your bookmark feature and there you’re done !

Instamojo Unveils InstaPay to Accumulate Online Payments

Instamojo is a well- launched platform to effortlessly collect payments online for digital items. Recently it has added a new feature known as Instapay that makes it very easier to deliver and collect payments online. Through Instapay, the sender only requires to have the recipient’s instamojo username to complete payment process.

Instapay takes the pressure of memorizing one’s bank account or any other vital details entirely off the desk. In that case, whether you are a service provider, freelancer or any professional who seeks to accept money – all you got to do is share your Instamojo username and let the payee make the payments smoothly. From the payee’s standpoint, they can use numerous payment methods comprising Credit and Debit cards or even Net banking.

instamojo-01

To practice Instapay, a business entity or individual must share their Instamojo username to the financier and customers can do money transmission to the account utilizing vivid payment methods like credit/debit cards or even net banking.

The cash is then transferred by electronic means to the end-user’s bank account.

Sampad Swain, Co-founder and CEO of Instamojo, said “Instapay may be somebody’s economic identity,”. Approximately 600 merchants have initiated utilizing the facility in the previous week or so, he further added Swain’s corporation freshly raised series from Bangalore based Kalaari Capital and few others. The corporation is seeking to knock into the small and medium business section, where many merchants have concern receiving or doing payments. The payments done on Instapay are then moved to associated bank account of the merchant or the respective service provider.

Now, here is an example, lets say we are making a payment to “Sachin Kumar” and his username is “sachin_k”, payee just requires to visit

http://Instamojo.com/@arun_p/ , where they will get subsequent screen. Just type the amount, the purpose of the payment and pay! The payment may perhaps be made via Bank account through NEFT or Debit/Credit card transaction. Once the payment is done effectively, the amount paid will pop up in his/her dashboard.

Benefits of Instapay !

The foremost reason why Instapay will charm to lot of individuals is for the reason that o it’s simple and easy to use. You have to simply recollect the username, and that’s it!

In addition to above features, it’s movable – for the individual who seeks to collect payments, they can merely share their url, username or link it from their website or purely share it on social networks like facebook and linkedin.

It has simply no upfront fees – Instamojo does not keep any upfront fees. Anybody on Instamojo can make their account and username and start gathering payments. They usually charge 1.9% for every fruitful sale on Instamojo – just in case, of Instapay the fees are projected to be alike (the website doesnt openly say the amount they charge per transaction).

We can positively say that Instapay is perhaps the simplest way of gathering and doing online payments. Next time you seek to gather payments from somebody, do give it a try!

As cell phone and internet dissemination upsurges, India has been gradually stirring from cash-driven economy to a cashless one. Even though cash still controls dealings in India, for the financial year end March 2015, it was first time, paperless transactions exceeded cheque-based transactions, as per data procured from India’s central bank.

The Indian govt has also been pushing e-transfers for recipients under govt schemes. Electronic payments are a great theme in PM Narendra Modi’s Jan Dhan Yojana also. The National Payments Corporation of India (NPCI}, an umbrella association run by India’s biggest banks, is also constructing a single platform for e-transactions.

Intel Reveals a Ring-Sized Wearable Platform – “Intel Curie”

intel-curie

Intel’s CEO tosses a coat button like item to reveal the brand new Intel Curie. A low-power hardware module, Intel curie is the one that can be utilized to build wearables out of objects like rings, bags, pendants, or glasses. With a measurement size of about 18 mm across, it hordes Quark SE architecture based processor, RAM of 80kb, 384kb inbuilt storage and an inbuilt less energy Bluetooth.

As per Intel, this is the first SOC rationale built for wearable and thus is intended to be power efficient. Regrettably, this also signifies that the SOC misses on a devoted app processor. As an alternative, it completely relies on the Micro Controller Unit (MCU) built in for all doling out functionalities.

The device it will control will not be as potent as android power-driven watches such as Sony smart watch or Galaxy Gear. In addition, the system also shows off a proprietary outline matching accelerator for gesture recognition, 6-way blend accelerometer and what more-gyroscope sensors. It has rather everything a wearable gadget requires comprising of battery charging circuitry.

In an official interview with Verge, it’s been told that Curie fundamentally gets you pretty far-off along towards a product, all you have to do is add your secret pulp on top of this and you’d have an exclusive wearable product.” Dissimilar to bands such as Xiaomi Mi Band that just accumulates and stores up all faction data and later on syncs with a phone, this Intel Curie will run an open-source software called Viper that will not only gather gesture data but also judiciously match outlines and be acquainted with activities such as step tracking or any hand gestures of the individual.

Though, the sad news is that this will not be subject to mass released for Developer community at present. In its place, Intel will collaborate with the likes of Oakley, Fitbit, Nike and few others to make moveable fitness tracker devices. While inaugurating the curie board, Intel also publicized gadgets that will be released in 3rd quarter of this year. Intel IQ software kit (A Separate SDK) will be packed with the board.

Despite the fact that this is not Intel’s first attempt at ‘Internet of Things’, it is positively the most momentous. Here is a plain comparison of the platforms as showcased by Anandtech publication:

Intel released a moveable PC at CES 2015 that can easily fit the size of a gum stick. Managing two variants- one for Windows 8.1 and another running Linux, the Intel Compute Stick advances near computer like specifications such as 1.8 GHz atom processor, 2gb ram (1GB for Linux version), WiFi 802.11 b/g/n, Bluetooth 4,0 and a mix of USB and micro USB ports. The PC sticks are priced at $149 and $89 in that order and has been released in March. This will optimistically fill the industry of a transportable yet potent PC that battles the likes of Amazon fire TV stick and Google Chromecast

It is fascinating to see how tininess of devices is occurring, all thanks to unexpected consumer-desire in wearables. The next year or two will certainly eyewitness some breathtaking things phenomenon in wearables space, and Intel with it’s Curie wishes to be in the thick of things!

Interestingly, Intel has been on far more on a trial bent over the preceding year, warming up its modernism muscles by revealing many exceptional concept products. For instance, a wireless charging bowl that was brought into limelight one year back at the firm’s keynote at CES and was one of the most roared-about products at the table.

Set Credentials using security.yml in Symfony 1.4

Symfony provides some cool configuration features that would allow you to minimize your coding part .  In this tutorial i would explain how to configure security.yml to set credentials for a different users.

Create a class file named account.class.php under apps/frontend/lib folder with content .The class below checks weather the user is admin and sets his credential as ‘admin’ . Update the class file as your requirement .

[php]

class account
{
public static function getLoginAdmin($username, $password)
{
// code to check for username and password in a particular table : ORM is doctrine
$usr = Doctrine::getTable(‘TableName’)
->createQuery(‘a’)
->where(‘a.adminuser = ?’,$username)
->andWhere(‘a.password = ?’,$password)
->execute();

$login_user = count($usr);

if($login_user > 0)
{
sfContext::getInstance()->getUser()->setAuthenticated(true);
sfContext::getInstance()->getUser()->addCredential(‘admin’);

return true;
}
else
{
return false;
}
}
public static function LogoutSession()
{
sfContext::getInstance()->getUser()->setAuthenticated(false);
sfContext::getInstance()->getUser()->clearCredentials();

sfContext::getInstance()->getUser()->getAttributeHolder()->removeNamespace(‘admin’);

return true;
}
}

[/php]

And in login action file after receiving username and password call the library function as shown below

[php]

$login_flag = account::getLoginAdmin($this->username,$this->password);

[/php]

and if $login_flag returns true you have successfully logged in else enter username or password is invalid .

You have done with the class file and action page . Now you need to configure security.yml .

Create a folder named config inside a module ( say for eg : under admin module ) with security.yml in it and paste the following code .

[html]

index:
is_secure: true
credentials: admin

[/html]

Now admin module can be accessed only by one with ‘admin’ credential .

You can flush the credential as

[php]

$logout = account::LogoutSession();

[/php]

You are done !

Live Character Counter as in Twitter using Jquery

In this tutorial i would explain how to implement live character counter using Jquery .

The package contains only a single file with 3parts a css part , javacript part and an html part

[css]

#bar
{
background-color:#5fbbde;
width:0px;
height:16px;
}
#barbox
{
float:right;
height:16px;
background-color:#FFFFFF;
width:100px;
border:solid 2px #000;
margin-right:3px;
-webkit-border-radius:5px;-moz-border-radius:5px;
}
#count
{
float:right; margin-right:8px;
font-family:’Georgia’, Times New Roman, Times, serif;
font-size:16px;
font-weight:bold;
color:#666666
}
#contentbox
{
width:450px; height:50px;
border:solid 2px #006699;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}

[/css]

Include jquery.js before you use the script .

[javascript]

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

[/javascript]

[javascript]

$(document).ready(function()
{
$("#contentbox").keyup(function()
{
var box=$(this).val();
var main = box.length *100;
var value= (main / 145);
var count= 145 – box.length;

if(box.length <= 145)
{
$(‘#count’).html(count);
$(‘#bar’).animate(
{
"width": value+’%’,
}, 1);
}
else
{
alert(‘ Full ‘);
}
return false;
});

});

[/javascript]

[html]

<div style="width:470px;margin-top:100px;">
<div id="count" align="right">145</div>
<div id="barbox"><div id="bar"></div></div>
</div>
<strong><lable>Enter Text : </label><strong><textarea id="contentbox"></textarea>

[/html]

You are done !

Thumbnail creation using uploadify.php

Hello friends i came across a good jquery flash file up-loader here . Do use it its simple and powerful .

The next main thing was generation of thumbnail using the same flash uploader after some homework found a solution for it . Do some simple updations in your existing code .

1. Create a folder named “thumbnails” under the upload folder .

2. Replace the code in uploadify.php [you can find it under scripts folder] with the following code .

[php]

if (!empty($_FILES))
{
$tempFile = $_FILES[‘Filedata’][‘tmp_name’];
$targetPath = $_SERVER[‘DOCUMENT_ROOT’] . $_REQUEST[‘folder’] . ‘/’;
$targetFile =  str_replace(‘//’,’/’,$targetPath) . $_FILES[‘Filedata’][‘name’];
move_uploaded_file($tempFile,$targetFile);
echo "1";
}
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3)))
{
case "jpg":
$image = imagecreatefromjpeg($targetFile);
break;
case "png":
$image = imagecreatefrompng($targetFile);
break;
case "gif":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}

$width = 80; //New width of image
$height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions

$src_w = $imgsize[0];
$src_h = $imgsize[1];

$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);

if($bool)
{
switch(strtolower(substr($targetFile, -3)))
{
case "jpg":
header("Content-Type: image/jpeg");
$bool2 = imagejpeg($picture,$targetPath."thumbnails/".$_FILES[‘Filedata’][‘name’],80);
break;
case "png":
header("Content-Type: image/png");
imagepng($picture,$targetPath."thumbnails/".$_FILES[‘Filedata’][‘name’]);
break;
case "gif":
header("Content-Type: image/gif");
imagegif($picture,$targetPath."thumbnails/".$_FILES[‘Filedata’][‘name’]);
break;
}
}

imagedestroy($picture);
imagedestroy($image);

echo ‘1’;

[/php]

You are done ! Hope it helped you .

Update Timeline using Jquery as in Twitter | Live Twitter Search using PHP

Hello friends back to blogging after sometime .  Recently i got a mail from one of my friend asking about how can we update a timeline using an animation effect as in twitter timeline .

Here i am giving you a code in jquery that would help you to implement the same .

The package contains 3 main files . 1.index.php 2.search.php and a 3.twitterapi.php

code within index.php

[html]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Twitter Search Flow</title>
<style type="text/css">
.woork{
color:#444;
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
width:600px;
margin: 0 auto;
}
.twitter_container{
color:#444;
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
width:450px;
margin: 0 auto;
background:#DEDEDE;
padding:8px;
}
.twitter_container a{
color:#0066CC;
}
.twitter_status{
height:60px;
padding:6PX;
border-bottom:solid 1px #DEDEDE;
background:#FFF;
}
.twitter_image{
float:left;
margin-right:14px;
border:solid 2px #DEDEDE;
width:50px;
height:50px;
}
.twitter_small{
font-size:11px;
padding-top:4px;
color:#999;
display:block;
}
#twitter-results{padding-top:8px;}
</style>
<script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var twitterq = ”;

function displayTweet(){
var i= 0;
var limit = $("#twitter-results > div").size();
var myInterval = window.setInterval(function () {
var element =  $("#twitter-results div:last-child");
$("#twitter-results").prepend(element);
element.fadeIn("slow");
i++;
if(i==limit){
window.setTimeout(function () {
clearInterval(myInterval);
});
}

},2000);
}

$("form#twittersearch").submit(function() {
twitterq = $(‘#twitterq’).attr(‘value’);

$.ajax({
type: "POST",
url: "search.php",
cache: false,
data: "twitterq="+ twitterq,
success: function(html){
$("#twitter-results").html(html);
displayTweet();
}
});
return false;
});

});

</script>
</head>

<body>
<div>
<strong>Try to search something on twitter:</strong><br />
<br/>
<form id="twittersearch" method="post" action="">
<input name="twitterq" type="text" id="twitterq" />
<button type="submit">Search</button></form>
<div id="twitter-results"></div>
</div>
</body>
</html>

[/html]

code within search.php

[php]

include(‘twitterapi.php’);

if($_POST[‘twitterq’]){
$twitter_query= $_POST[‘twitterq’];
$search = new TwitterSearch($twitter_query);
$results = $search->results();

foreach($results as $result){
echo ‘<div style="display:none;">’;
echo ‘<img src="’.$result->profile_image_url.’">’;
$text_n=toLink($result->text);
echo $text_n;
echo ‘<span>’;
echo ‘<strong>From:</strong> <a
href="http://www.twitter.com/’.$result->from_user.’">’.$result->from_user.'</a>:
‘;
echo ‘<strong>at:</strong> ‘.$result->created_at;
echo ‘<input type="hidden" value="’.$result->id.’"></input>’;
echo ‘</span>’;
echo ‘</div>’;
}
}

[/php]

Download the source package for jquery.js and twitterapi.php .

Rewrite .php extension with .html using .htaccess | URL rewriting using .htaccess.

I had to implement URL rewriting in my last project . After some browsing found that it can be implemented using .htaccess file .

Ok fine . we can start from the basics of creating a .htaccess file .

In windows one cannot create .htaccess file directly . You can either create a “htaccess” file on windows upload it and rename it to “.htaccess” or create a notepad file and save it as “.htaccess” file .

Begin Rewriting

Whenever you use mod_rewrite (the part of Apache that does all this magic), you need to do

[html]
Options +FollowSymlinks
RewriteEngine on
[/html]

before any ReWrite rules. note: +FollowSymLinks must be enabled for any rules to work, this is a security requirement of the rewrite engine. Normally it’s enabled in the root and you shouldn’t have to add it, but it doesn’t hurt to do so, and I’ll insert it into all the examples on this page, just in case*.

The next line simply switches on the rewrite engine for that folder. if this directive is in you main .htaccess file, then the ReWrite engine is theoretically enabled for your entire site, but it’s wise to always add that line before you write any redirections, anywhere.

Simple Rewriting

You can rewrite all .php files with .html tag . Use following code to implement the same .

[html]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
[/html]

Now try .html with .php extension . ie , help.html would call help.php

Reading remote files using PHP | Manage remote files | Read data from URL using PHP

Recently I had to do a project in which the task to read files from a remote server. On browsing on net I found different resources , I am putting it together for your reference.

Getting the title of a Remote Page

Use the following code to scrap page title .

[php]
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
echo "Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
/* This only works if the title and its tags are on one line */
if (eregi ("(.*)", $line, $out)) {
$title = $out[1];
break;
}
}
echo "Page Title : ".$title;
fclose($file);
?>
[/php]

Reading the contents of a file into Array

File function returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Each line in the resulting array will include the line ending, so you still need to use rtrim() if you do not want the line ending present.

[php]

<?php
// Get a file into an array.  In this example we’ll go through HTTP to get
// the HTML source of a URL.
$lines = file(‘http://www.example.com/’);

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo “Line #<b>{$line_num}</b> : ” . htmlspecialchars($line) . “<br />\n”;
}
?>

[/php]

Reading the contents of a file into a string
Functions file_get_contents() returns the file in a string. This is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.

[php]

<?php
$content_string = file_get_contents(‘www.example.com/products.html’);
?>

[/php]

Storing data on a remote server

You can also write to files on an FTP server (provided that you have connected as a user with the correct access rights). You can only create new files using this method; if you try to overwrite a file that already exists, the fopen() call will fail. You need to specify the username and password within the URL, such as ‘ftp://user:password@ftp.example.com/path/to/file’.

[php]

<?php
$file = fopen (“ftp://ftp.example.com/incoming/outputfile”, “w”);
if (!$file) {
echo “<p>Unable to open remote file for writing.\n”;
exit;
}
/* Write the data here. */
fwrite ($file, $_SERVER[‘HTTP_USER_AGENT’] . “\n”);
fclose ($file);
?>

[/php]