> November 2013 ~ Online tutorial

75% discount Hosting plan sale in Hostgator

75% discount Hosting plan sale in Hostgator

HostGator is one of the world's top 10 largest web hosting companies and offers the Black friday offer today.
Offer In Hostgator

Hostgator is offering 1 hour flash sale on Black friday, and you can grab hosting for as low as $1.24/month.
Discount: Various discount from Black friday to Cyber monday.
Start date: Today
End date: December 2nd


Click To Get

PHP interview Question with answer

PHP interview Question with answer

1)<?php
$varA=one;
$varB=&$varA;
$varA=two;
print $varB;
?>

Output:
2

It is result is Two because $varB holds the reference of $varA value an dboth $varA and $varB poin the same value.

2)<?php
$num1=6;
$num2=5;
$val=(num1>$num2)?$num1:$num2;
echo "Greatest of no".$val;num2;
?>

Output:
6
It is greatest of two number in the given number.

3)what is print_r()?

The print_r() is used to print out the entire content of array.
<?php
$fruit=array("orange","apple","mango");
print_r($fruit);
?>

4)What happened below code
<?php
print "type(152).gettype(152)."\n";
?>

Answer:

it is return the 152 as an Integer value.gettype() is used to get the datatype.

5)How do find the Ip address of remote machine?

Answer:

<?php
echo "your ip address is ".$SERVER['REMOTE_ADDR'];
?>

6)<?php
echo ucfirst("helloworld");
?>
what happened in this code?

Answer:

It is return the output Hello world.the ucfirst() is used to convert the first character in to Uppercase.

7)Difference between include() and require()?

In include() function if can't include the file it is generate error but continue the execution of program but require() function if can't include the file it is generate fatal error in script.

8)How destroy the session in PHP?

In session we are using unset() or session_destroy() function which is used to destroy the session in PHP.

9)What is use of explode() in PHP?
explode() function is used to convert string into array.

10)How do connect PHP with Mysql query?

$mysql_connect("address","username","password")

How do Upload File using PHP

How do Upload File using PHP

In PHP we are using two file which used upload file in the server.First one Html file and another one is PHP file .

In the Html file we are going get file content and PHP file we are process it and Upload into Particular file path.

Coding

In the coding section we are show First html file.In the html file we are going to get file and sent to php file using POST method.Here code for HTML file.


Upload.html:

1)In the form enctype/form data encding when submitting to the server.


<html>
<body>
<form enctype="multipart/formdata" action="saveupload.php" method="post">
<input type="file" name="fileToUpload">
<input type="submit" value="UploadFile">
</form>
</body>
</html>

saveupload.php:


1)$_FILES["file"]["name"] it is used get the name of file
2)$_FILES["file"]["type"] it is used to get type of file  
3)$_FILES["file"]["size"]  it is used to get size of file 
4)$_FILES["file"]["tmp_name"]  it is give tmp name of file which is ued to store the file in folder.


<?php

echo "<table border=\"1\">";
echo "<tr><td>Client Filename: </td>

   <td>" . $_FILES["file"]["name"] . "</td></tr>";

echo "<tr><td>File Type: </td>
   <td>" . $_FILES["file"]["type"] . "</td></tr>";
echo "<tr><td>File Size: </td>
   <td>" . ($_FILES["file"]["size"] / 1024) . " Kb</td></tr>";
echo "<tr><td>Name of Temp File: </td>
   <td>" . $_FILES["file"]["tmp_name"] . "</td></tr>";
echo "</table>";

move_uploaded_file($_FILES["file"]["tmp_name"], "C:/upload/" . $_FILES["file"]["name"]);

?>

move_uploaded_file(dest_file,source_file)

Here Upload is folder we can create in you local computer it is save the file.