Hey Developers,

Happy to bring new post after a while. Today I was working on one of my project where it was required to upload/move a file to a FTP server using PHP from your local folder. Initially was bit scared how to proceed with the uploading of a file to a remote FTP server. But when I started working on I googled and with friends help got to know how to execute that task. I can tell you guys its very simple, just you need to know is few basic PHP commands for performing that functionality. Here it how it goes:-

For Uploading file on FTP You must have some access credentials required for it like Hostname, Username and Password of the remote server where you want to move your local files to. So if you have all those details then it is very simple to deal with the issue.

Follow the following steps:-

1) Assign the FTP access credentials to PHP variables as follows:-

(Note following is just a example/dummy values)

$hostName = 'www.example.com';
$userName = 'chandreshmodi';
$passWord = 'xyz12345';

2) Now assign directory of the remote server to a PHP variable where you want to move your file:-

$destinationDirectory = '/projectname/flodername';

3) Now assign directory of the local server to a PHP variable from where you want to move your file:-

$localDirectory = "/usr/local/temp"; // define this as per local system

4) Get the temporary file name for the uploaded file

$tmpName = basename($_FILES['file']['tmp_name']);

5) Copy uploaded file into current directory. Perhaps you will use following function for it:-

move_uploaded_file($_FILES['file']['tmp_name'], $localDirectory."/".$tmpName) or die("Cannot move uploaded file to working directory");

6) Open connection for the FTP server

$connection = ftp_connect($hostName) or die ("Cannot initiate connection to host");

7) Send access parameters to login to FTP Server

ftp_login($connection, $userName, $passWord) or die("Cannot login");

8 ) Now Once You are logged in to FTP, you can perform file upload to remote server using php “ftp_put”

$upload =
ftp_put($conn, $destinationDirectory."/".$_FILES['file']['name'],

9) Now Check Upload Status if your file got uploaded successfully or not:-

if (!$upload) {

echo "Cannot upload";

} else {

echo "Upload complete";


10) Close the FTP connection that you have opened:-


That’s it If you have all the valid credentials and if you follow all the steps mentioned above properly, i guess you would end up performing the file uploading task quite easily. If still any problems you comment on the post and I woul love to help you out.

Happy Rocking and Happy Coding.🙂

Cloud Computing” many of you would have heard this terminology somewhere somehow. But you may not be familiar with it. So What it is?? What it does?? What is the hype all it is about Cloud Computing?? All this question may arise in your central CPU called Mind..:-)

Basically Cloud computing is a technology that uses the Internet and central remote servers to maintain data and applications. It allows site users to use applications without any installation and access their personal files at any computer  remotely with an Internet connection. This technology provides efficient computing by centralizing storage of data plus less memory usage, high processing speed and greater bandwidth.


Life before cloud computing :-

A Normal Business applications that one have is always cumbersome and expensive. The amount  of hardware and software aid required to maintain and run  them  was painstaking. It needed a whole team for  installing, configuring, testing, running, and updating those hardwares and softwares.

So far you have got an Idea that Cloud Computing deals with delivering hosted services over the Internet. Now may be some of you would be perplexed and would be asking yourself then how does it differ from traditional way of hosting services. Isn’t it same?? So, to answer your question, A cloud service has three distinct characteristics that differentiate it from traditional hosting :-

a) It is sold on demand, typically by the minute or the hour.

b) It is elastic means a user can have as much or as little of a service as they want at any given time

c) The service is fully managed by the provider (the consumer needs nothing but a personal computer and Internet access).

Thus the above 3 main characteristic differentiates the cloud computing from traditional way of hosting Internet services.

A simple example of cloud computing in daily life is Yahoo mail or Gmail. You don’t need any softwares to run them. What you really needs is a computer plus an Internet Connection. That’s it. Am I wrong?? Obviously not! With that resource you can start sending mails and chat and do whatever you want to do. The server and email management is all on the cloud and is managed by cloud service provider like yahoo, google etc. Consumer don’t need to bother how its happening, they can simply enjoy using service. Its as simple as that :- “If You want to eat Vegetable..Would you buy a farm.” Similarly the analogy applies for cloud computing too. If  you want to use any service why would you take trouble installing hardware and softwares for it, when cloud computing does it for you.

Above attached diagram shows how cloud computing basically works. You can see a cloud at center. This cloud actually contains all the softwares and hardwares(as described above) that an application needs to run on your machine.Mobile, database, PC are all the end users which uses the application installed in a cloud.

I hope  the description and the explanation given would be ample to help you understand what is really a cloud computing is and what it does! Even though if any further doubts or questions are there, these blog is open for comments and I will try my best to sort out your queries.



What is Phishing?

Posted: January 21, 2011 in MISCELLANEOUS

Many of you people would have heard this term Phishing. Some of you would be knowing what actually it is?? Some of you wont be knowing what is it?? So people who don’t know what is phishing, please don’t interrelate it with fishing. Their is nothing similar in between two except their pronunciation which is almost same. Now you would be thinking if they are not same then what the hell phishing is?? Relax and just Chill out..:-)… The following article will completely explain you what is phishing? How it is done? What are the effects?? Just tighten up your seat belts and read it carefully..:-)

First of all we should know what Fishing is

What is Phishing?
Phishing is an e-mail fraud designed to steal your web identity and capture your personal data like Credit/Debit Card numbers, bank account information, or other sensitive financial information. Phishing scams have rocked Internet users for some time now.
Cyber-criminals write programs and send junk/spam mails to user which in turn tells you enter your banking/personal details. If you provide your details, you will be almost screwed. So be careful.
Following is a sample example how a Phishing mail may looks like. The example is an excerpt that I have received from HDFC bank.

1. The phishing email you receive might look like the one shown below.


2.If you click on the CLICK HERE option, it will take you to a bogus income tax site as shown below:

3. You will be given options for various Indian Banks to choose from.

4. Whichever bank you choose, your Internet banking passwords and additional authentication details will be compromised.
5. Once you have entered your details, you will be given a confirmation which might look as shown below.

Thus, you will end up gifting your confidential banking details to cyber criminals. They can misuse those details. So, one should be careful while clicking on a link in an email which is not trustworthy. Don’t allow anyone to access your details until unless you are sure that the source to which you are providing details is genuine.

Several examples are live out  in market where Bank customers have been fooled by this phishing mails/scam. Bank of America, US Bank,  Bank of  Montreal, ANZ Bank of Australia are the examples of these scam.

Not only these their are commercial institutions which have been affected by the phishing. For eg:- Paypal, ebay, MSN, Yahoo..

All Internet users are poilitical targets. We can all be fooled. It take only few minutes to get fooled on a bad day. So be careful while clicking on any link that takes you other website and ask your confidential details.

Happy Surfing..:-)

Can a Array be stored In A Session?

Posted: January 20, 2011 in PHP STUFF

Here we go guys. Storing an array in a session. Can we do it? Is it possible?? I came across this question once when I have to work upon something which required an array to be stored in a session variable. Since before that I have used session variable to store a string or some value but for sure not an array. But this time I had to play around with an array. So, after doing some searches I came across solution which I was looking for. The solution goes here :-

// begin the session

// create an array
$array=array('cricket', 'football', 'tennis', 'badminton', 'golf', 'squash', 'chess', 'basketball');

// put the array in a session variable

// a little message to say we have done it
echo 'Putting array into a session variable';

As simple as that. You would be thinking dude that was so easy assigning an array. Yeah that was really very simple. Now some of you would be thinking after assigning this array how do I access the value of array from the session variable. Don’t bother that is as simple as the assigning of array to the session. I hope all of you would be familiar with Foreach Keyword in PHP. I used the same Keyword for accessing the value of array from the session variable. Below is the code which I used for it :-

// begin the session
// loop through the session array with foreach
foreach($_SESSION['animals'] as $key=>$value)
    // and print out the values
    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' ';

That’s all that I have been requiring to accomplish my task at work. Hope it would help you also if You come across such situation where you require to assign an array to a session variable.

PHP Namespaces and How to Implement?

Posted: January 19, 2011 in PHP STUFF

So here we go guys…

Namespaces all the talks happening in programming world. What are actually Namespaces??

In the broadest definition namespaces are a way of binding or encapsulating items.
For example, in any operating system, directories serve to group related files, and act as a namespace for the files within them. As a concrete example, the file foo.txt can exist in both directory /home/greg and in /home/other, but two copies of foo.txt cannot co-exist in the same directory. In addition, to access the foo.txt file outside of the /home/greg directory, we must prepend the directory name to the file name using the directory separator to get /home/greg/foo.txt. This same principle extends to namespaces in the programming world.

In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions:

1. Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.
2. Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code.

Why Do We Need Namespaces?

As the size of your PHP code increases, there is risk that you end up accidentally re-defining a function or class name that has been declared before. That will result in errors in your PHP code. So to avoid Name collision problems namespaces have been introduced.

How are Namespaces Defined?

Namespaced code is defined using a single namespace keyword at the top of your PHP file. It must be the first command and no non-PHP code, HTML, or white-space can precede the command, e.g.

  // define this code in the 'MyStuff' namespace  
     namespace MyStuff1;  
     namespace MyStuff2;
     namespace MyStuff3; 

PHP allows you to define a hierarchy of namespaces so libraries can be sub-divided. Sub-namespaces are separated using a backslash (\) character,
e.g. MyProject\SubName, MyProject\Database\MySQL.

So above was a brief expanation regarding the namespace. What they are, their use, how to define and declare?. Hope now you would be comfortable using the namespaces in your code and hence avoid name conflicts.

Happy Coding🙂

Parsing a URL in PHP

Posted: January 18, 2011 in PHP STUFF

Hi Guys,

Once at work I had got an issue where parsing of a URL was required. I was using PHP as a programming language. After few searches I came across a very good article that helped in performing my task.

Here is a simple function which can be used to Parse the URL.

parse_url is a built in PHP function which can be used to parse url and get the type of request like whether its http or https or ftp, gives the domain name like http://www.google.com and path and the query.

for eg. lets consider this url – http://www.myexample.com/category.php?cat_id=6

$url = “http://www.myexample.com/category.php?cat_id=6&#8221;;
$parts = parse_url($url);

In http://www.myexample.com/category.php?cat_id=6 this url

if you execute parse_url function then it will show the following result.

 Output :-
scheme - http
url - www.myexample.com
path - /category.php
query - cat_id=6

That’s it… That is what I wanted for performing my task. You can also use this function in PHP if you come across a situation where you have to parse a url.

Happy Coding🙂

MySQL’s REGEXP function is very useful when u want search a string, but it would not be appropriate to use if performance is taken into account.

Recently I had a situation at work where I was in need to do a first name / last name search across a single name field. Due to database design, the name field was in the form “lastname, first names”. Initially I used REGEXP to come up with something like this:

Select table1.some-data, table2.some-other-data
table1, table2
table1.name REGEXP "^[ a-z]{0,},[ a-z]{0,}'.$firstName.'[ a-z]{0,}$"
table1.name REGEXP "^[ a-z]{0,}'.$lastName.'[ a-z]{0,},[ a-z]{0,}$"
table1.key = table2.foreignKey

Our testing showed that this query produced a good quality result for name searches, but I had a gut feeling it would slow the database server considerably when under a bit of load.

Testing using JMeter confirmed this hunch and I was faced with the task of optimising the query without affecting the quality of the results.

What to do? What would give the pattern-matching punch of REGEXP without killing the server?

Enter the LIKE function. I’ve used LIKE before but didn’t realise how powerful (and fast) it was. After a bit of tweaking I cam up with the following:

Select table1.some-data, table2.some-other-data
table1, table2
table1.name LIKE "%,%'.$firstName.'%"
table1.name LIKE "%'.$lastName.'%,%"
table1.key = table2.foreignKey

I had (falsely) thought initially that LIKE‘s wild card characters (the “%” in the query) could only occur at the start or end of a query, but it turns out they can be used for all sorts of pattern matching goodness. The query using LIKE turned out the same results as the query using REGEXP, only it was at least 10 times faster.

The downside with LIKE‘s pattern matching (which didn’t affect my query) is that it’s wild card will match any character, whereas REGEXP can be tuned using normal regular expressions to providfe much more granular query control.

If you just need fast, ‘any character’ pattern matching though, LIKE is your friend.

Enjoy SQL’ing..;-)