SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN
B.C.A. Semester – VI
BCA-604 : Building Application Using PHP & ASP.NET
Teaching Scheme
(per week)

Examination Scheme

Teaching Scheme
(per semester)

INT

EXT

TOTAL

Th.
(hours)

Pr.
(hours)

Total
Hours

Credit

Th.
(marks)

Pr.
(marks)

Th.
(marks)

Pr.
(marks)

Th.
(marks)

Pr.
(marks)

--

4

40

4

--

30

--

70

--

100

University Examination Duration: 3 Hours (Per Batch)
(Practical List) : PHP (50%)
1. Write a PHP program to display “Hello World” Message on Screen.
Practical-1.php
<html>
<head>
<title>Practical-1</title>
</head>
<?php
echo "<b>Hello</b> <i>World</i>";
?>
<body>
</body>
</html>
Or
Practical-1a.php
<?php
echo "<b>Hello</b> <i>World</i>";
?>
Output:
Hello World

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 1 
2. Write a PHP program to display the today’s date and current time.
Practical-2.php
<?php
print strftime('%c');
echo "<br />";
print strftime('%d/%m/%Y');
echo "<br />";
print strftime('%A, %d %B - %Y');
echo "<br />";
echo "<b>Current Day, Date and Time is:</b> " . date("D M d, Y G:i A");
?>
Output:
01/19/14 11:31:16
19/01/2014
Sunday, 19 January - 2014
Current Day, Date and Time is: Sun Jan 19, 2014 11:31 AM

3. Write a PHP program to display the Fibonacci series.
Practical-3.php
<?php
$count = 0;
$no1 = 0;
$no2 = 1;
$tot = 0;
while($count <= 10)
{
echo $tot . "<br />";
$no1 = $no2;
$no2 = $tot;
$tot = $no1 + $no2;
$count ++;
}
?>
Or
Practical-3a.php
<?php
$number=10;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 2 
$firstno=0;
$secondno=1;
$nextno=0;
$cnt=0;
echo "Fibonacci Series<br><br>";
for($cnt=0;$cnt<=$number;$cnt++)
{
if($cnt<=1)
$nextno=$cnt;
else
{
$nextno = $firstno + $secondno;
$firstno = $secondno;
$secondno = $nextno;
}
echo $nextno . "<br>";
}
?>
or
practical-3b.php
<?php
$number=10;
$i=0;
$cnt=0;
echo "Fibonacci Series<br><br>";

for($cnt=0 ;$cnt<=$number;$cnt++)
{
echo fibonacci($i) . "<br>";
$i++;
}
function fibonacci($number)
{
if ( $number == 0 )
return 0;
else if ( $number == 1 )
return 1;
else
return ( fibonacci($number-1) + fibonacci($number-2) );
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 3 
?>
Output:
0
1
1
2
3
5
8
13
21
34
55

4. Write a PHP program to calculate sum of given number.
Practical-4.php
<?php
$val1=10;
$val2=10;
function sum($val1,$val2)
{
$total=$val1+$val2;
return $total;
}
echo "<b>Sum using Function : </b>" . sum($val1,$val2);
$sum=$val1 + $val2;
echo "<br />";
echo "<b>Sum is :</b> $sum";
?>
Output:
Sum using Function : 20
Sum is : 20

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 4 
5. Write a PHP Program that will use the concept form.
Practical-5.php
<html>
<head>
<title>Practical-5 Form Concept</title>
</head>
<body>
<form name="frmdemo" action="practical-5a.php" method="post" >
<fieldset>
<legend>Enter Your Details</legend>
<table width="250px" border="2" align="center">
<tr>
<td align="right">Name</td>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<td align="right">Contact No</td>
<td><input type="text" name="txtcno"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 5 
Practical-5a.php

<?php
if(isset($_REQUEST['submit']))
{
$name=$_REQUEST['txtname'];
$cno=$_REQUEST['txtcno'];
echo "<b>Your Name is: </b>" . $name . "<br>";
echo "<b>Contact No: </b>" . $cno;
}
else
{
echo "Go Back and Press Submit button";
}
?>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 6 
6. Write a PHP program to read the employee detail using form component.
Practical-6.php
<html>
<head>
<title>Practical-6 Employee Form</title>
</head>
<body>
<form name="empfrmdemo" action="practical-6a.php" method="post" >
<fieldset>
<legend>Grow More Computer Science</legend>
<table width="360px" border="2" align="center">
<caption><b>Enter Employee Detail...</b></caption>
<tr>
<td align="right">Employee Name</td>
<td><input type="text" name="empname" size="30px"></td>
</tr>
<tr>
<td align="right">Address</td>
<td><textarea name="empadd" cols="23"></textarea></td>
</tr>
<tr>
<td align="right">Department</td>
<td><select name="empdept">
<option value="BCA" selected>BCA</option>
<option value="PGDCA">PGDCA</option>
<option value="M.Sc.(CA&IT)">MSC(CA/IT)</option>
</select>
</td>
</tr>
<tr>
<td align="right">Designation</td>
<td><select name="empdes">
<option selected="" value="Principal">Principal</option>
<option value="Professor">Professor</option>
<option value="Asst.Professor">Asst.Professor</option>
<option value="Lecturer">Lecturer</option>
<option value="Clerk">Clerk</option>
</select>
</td>
</tr>
<tr>
<td align="right">Male/Female</td>
<td>
<input type="radio" name="gender" value="male" checked="checked">Male<br>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 7 
<input type="radio" name="gender" value="female">Female
</td>
</tr>
<tr>
<td align="right">Favourite Subjects</td>
<td>
<input type="checkbox" name="favsub[]" value="Hacking" checked="checked" />Hacking<br />
<input type="checkbox" name="favsub[]" value="Photoshop" />Photoshop<br />
<input type="checkbox" name="favsub[]" value="Forensic" checked="checked"/>Forensic<br />
<input type="checkbox" name="favsub[]" value="C Language" />C Language<br />
<input type="checkbox" name="favsub[]" value="PHP" checked="checked"/>PHP
</td>
</tr>
<tr>
<td align="right">Contact No</td>
<td><input type="text" name="empcno" size="30px"></td>
</tr>
<tr>
<td align="right">E-Mail</td>
<td><input type="text" name="empmail" size="30px"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" name="emppass" size="30px"></td>
</tr>
<tr>
<td align="right">Upload Photo</td>
<td><input type="file" name="empphoto" accept="image/*" size="30px"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="empid" value="101">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 8 
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 9 
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 10 
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 11 
7. Write a PHP program to demonstrate the use of array.
Practical-7.php
<?php
/*Indexed Array*/
// Indexed Array using Method-1
$gm=array("BCA","PGDCA","MSCIT");
echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . ".";
echo "<br>";
//Indexed Array using Method-2
$gm[0]="BCA";
$gm[1]="PGDCA";
$gm[2]="MSCIT";
echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . ".";
echo "<br>Elements in Array:";
$arrsize=count($gm);
for($cnt=0;$cnt<$arrsize;$cnt++)
{
echo "<br>";
echo "<b>" . $gm[$cnt] . "</b>";
}
echo "<br>";
/*Associative Array*/
// Associative Array using Method-1
$gm=array("d1"=>"BCA","d2"=>"PGDCA","d3"=>"MSCIT");
echo "Degree is " . $gm['d1'] ;
echo "<br>";
//Associative Array using Method-2
$gm['d1']="BCA";
$gm['d2']="PGDCA";
$gm['d3']="MSCIT";
echo "Degree is " . $gm['d2'] ;
echo "<br>";
foreach($gm as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 12 
Output:
I like BCA, PGDCA and MSCIT.
I like BCA, PGDCA and MSCIT.
Elements in Array:
BCA
PGDCA
MSCIT
Degree is BCA
Degree is PGDCA
Key=d1, Value=BCA
Key=d2, Value=PGDCA
Key=d3, Value=MSCIT

8. Write a PHP program to prepare student Mark sheet using Switch statement.
Practical-8.php
<html>
<head>
<title>Practical-8 Marksheet</title>
</head>
<body>
<form name="frmdemo" action="practical-8a.php" method="post" >
<fieldset>
<legend align="center">Enter Your Name with Marks Detail</legend>
<table width="250px" border="2" align="center">
<tr>
<td align="right">Name</td>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<td align="right">Subject-1</td>
<td><input type="text" name="txtsub1"></td>
</tr>
<tr>
<td align="right">Subject-2</td>
<td><input type="text" name="txtsub2"></td>
</tr>
<tr>
<td align="right">Subject-3</td>
<td><input type="text" name="txtsub3"></td>
</tr>
<tr>
<td align="right">Subject-4</td>
<td><input type="text" name="txtsub4"></td>
</tr>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 13 
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 14 
Practical-8a.php
<?php
if(isset($_REQUEST['submit']))
{
$name=$_REQUEST['txtname'];
$sub1=$_REQUEST['txtsub1'];
$sub2=$_REQUEST['txtsub2'];
$sub3=$_REQUEST['txtsub3'];
$sub4=$_REQUEST['txtsub4'];
echo "<b>Your Name is: </b>" . $name . "<br>";
echo "<b>Your Marks Detail: </b> <br>";
echo "Subject-1: " . $sub1 . "<br>";
echo "Subject-2: " . $sub2 . "<br>";
echo "Subject-3: " . $sub3 . "<br>";
echo "Subject-4: " . $sub4 . "<br>";
$total=$sub1+$sub2+$sub3+$sub4;
echo "Total Marks: " . $total . "<br>";
$per=$total/4;
echo "Percentage: " . $per . "%<br>";
switch($per)
{
case $per<35:
echo "Grade: F" . "<br>";
break;
case $per>=35 && $per<=50:
echo "Grade: D" . "<br>";
break;
case $per>50 && $per<=60:
echo "Grade: C" . "<br>";
break;
case $per>60 && $per<=70:
echo "Grade: B" . "<br>";
break;
case $per>70 && $per<100:
echo "Grade: A" . "<br>";
break;
default:
echo "Invalid.... or out of limit";
break;
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 15 
else
{
echo "Go Back and Press Submit button";
}
?>
Output:
Your Name is: Hitesh Patel
Your Marks Detail:
Subject-1: 40
Subject-2: 40
Subject-3: 40
Subject-4: 40
Total Marks: 160
Percentage: 40%
Grade: D

9. Write a PHP program to generate the multiplication of matrix.
Practical-9.php
<?php
$p = array();
$p[] = array(1,3,-4);
$p[] = array(1,1,-2);
$p[] = array(-1,-2,5);
$q = array();
$q[] = array(8,3,0);
$q[] = array(3,10,2);
$q[] = array(0,2,6);
echo "matrix 1<br/>";
echoMatrix(3, $p);
echo "<br/>";
echo "matrix 2<br/>";
echoMatrix(3, $q);
echo "<br/>";
$r = matrixMultiply(3, $p, $q);
echo "result of matrix multiply<br/>";
echoMatrix(3, $r);

function echoMatrix($N, $r)
{
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 16 
for($i=0; $i<$N; $i++)
{
for($j=0; $j<=$N; $j++)
{
if ($j==$N)
{
echo "<br>";
}
else
{
echo $r[$i][$j];
}
if ($j<($N-1))
{
echo ", ";
}
}
}
}
function matrixMultiply($N, $p, $q)
{
//init result
$r = array();
for($i=0; $i<$N; $i++)
{
$t = array();
for($j=0; $j<$N; $j++)
{
$t[] = 0;
}
$r[] = $t;
}
//do the matrix multiply
for($i=0; $i<$N; $i++)
{
for($j=0; $j<$N; $j++)
{
$t = 0;
for($k=0; $k<$N; $k++)
{
$t += $p[$i][$k] * $q[$k][$j];
}
$r[$i][$j] = $t;
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 17 
//return result
return $r;
}
?>
Output:

Practical-9a.php
<html>
<head>
<title>Matrix Multiplication</title>
</head>
<body>
<form name="matrix" action="practical-9b.php" method="get">
<table border="2" cellpadding="2" cellspacing="3">
<caption><b>Please Enter 3x3 Matrix</b></caption>
<tr>
<td rowspan="3">Matrix-A</td>
<td>
<input name="a11" type="text" style="width: 50px"></td>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 
Page No. 18 
<td>
<input name="a12" type="text" style="width: 50px"></td>
<td>
<input name="a13" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="a21" type="text" style="width: 50px"></td>
<td>
<input name="a22" type="text" style="width: 50px"></td>
<td>
<input name="a23" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="a31" type="text" style="width: 50px"></td>
<td>
<input name="a32" type="text" style="width: 50px"></td>
<td>
<input name="a33" type="text" style="width: 50px"></td>
</tr>
<tr>
<td rowspan="3">Matrix-B</td>
<td>
<input name="b11" type="text" style="width: 50px"></td>
<td>
<input name="b12" type="text" style="width: 50px"></td>
<td>
<input name="b13" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="b21" type="text" style="width: 50px"></td>
<td>
<input name="b22" type="text" style="width: 50px"></td>
<td>
<input name="b23" type="text" style="width: 50px"></td>
</tr>
<tr>
<td>
<input name="b31" type="text" style="width: 50px"></td>
<td>
<input name="b32" type="text" style="width: 50px"></td>
<td>
<input name="b33" type="text" style="width: 50px"></td>
</tr>
<tr>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 19 
<td align="center" colspan="4">
<input name="Submit" type="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
Output

Practical-9b.php

<?php
if(isset($_REQUEST['submit']))
{
$a = array();
$a[] = array($_REQUEST['a11'],$_REQUEST['a12'],$_REQUEST['a13']);
$a[] = array($_REQUEST['a21'],$_REQUEST['a22'],$_REQUEST['a23']);
$a[] = array($_REQUEST['a31'],$_REQUEST['a32'],$_REQUEST['a33']);
$b = array();
$b[] = array($_REQUEST['b11'],$_REQUEST['b12'],$_REQUEST['b13']);
$b[] = array($_REQUEST['b21'],$_REQUEST['b22'],$_REQUEST['b23']);
$b[] = array($_REQUEST['b31'],$_REQUEST['b32'],$_REQUEST['b33']);
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 20 
echo "Matrix-A<br/>";
dispmatrix(3, $a);
echo "<br/>";
echo "Matrix-B<br/>";
dispmatrix(3, $b);
echo "<br/>";
$r = matrixMultiply(3, $a, $b);
echo "Matrix Multiplication<br/>";
dispmatrix(3, $r);
}
else
{
header('location:practical-9a.php');
}
function dispmatrix($N, $r)
{
for($i=0; $i<$N; $i++)
{
for($j=0; $j<=$N; $j++)
{
if ($j==$N)
{
echo "<br>";
}
else
{
echo $r[$i][$j];
}
if ($j<($N-1))
{
echo ", ";
}
}
}
}
function matrixMultiply($N, $a, $b)
{
//init result
$r = array();
for($i=0; $i<$N; $i++)
{
$t = array();
for($j=0; $j<$N; $j++)
{
$t[] = 0;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 21 
}
$r[] = $t;
}
//do the matrix multiply
for($i=0; $i<$N; $i++)
{
for($j=0; $j<$N; $j++)
{
$t = 0;
for($k=0; $k<$N; $k++)
{
$t += $a[$i][$k] * $b[$k][$j];
}
$r[$i][$j] = $t;
}
}
//return result
return $r;
}
?>
Output:

 

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 22 
10. Write a PHP program to send Mail from PHP Script.
Practical-10.php
<?php
error_reporting(0);
$to = "me@localhost";
$subject = "This is subject Subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc@somedomain.com rn";
$header = "Cc:afgh@somedomain.com rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
Output:
Message sent successfully...

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 23 
11. Write a PHP Program for Create, Delete, and Copying file from PHP Script.
practical-11a.php
// Enter File Name to Check Whether it is Exists or Not
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11a1.php" method="post" name="filehand">
Enter File Name to Check Whether it is Exists or Not.<br />
<input type="text" name="filename" /><br />
<input type="submit" name="checkfile" value="Check File" />
</form>
</body>
</html>
Output:

practical-11a1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not.
if(isset($_REQUEST['checkfile']))
{
if (file_exists($filename))
{
echo "The file $filename exists". "<br>";
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 24 
}
else
{
echo "The file $filename does not exists". "<br>";
}
}
?>
Output:

practical-11b.php
//Create Blank File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11b1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click Here to Create Blank File<br />
<input type="submit" name="createfile" value="Create File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 25 
Output:

practical-11b1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if it is not exists then create new blank file
if(isset($_REQUEST['createfile']))
{
if (file_exists($filename))
{
echo "The file $filename exists". "<br>";
}
else
{
$handle = fopen($filename, 'w') or die('Cannot open file: '.$filename);
//Check Whether the file is created or nor.
if (file_exists($filename))
{
echo "The $filename file Successfully Created". "<br>";
}
else
{
echo "Error While Creating $filename". "<br>";
}
}
}
?>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 26 
Output:

practical-11c.php
//Create, Open File and Save Data
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11c1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Please Enter Text to save in selected file<br />
<textarea name="filedata" cols="20" rows="5"></textarea><br />
<input type="submit" name="savefile" value="Create/Save/Append File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 27 
Output:

practical-11c1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exist it append the file. if not, then create new file and store data.
if(isset($_REQUEST['savefile']))
{
if (file_exists($filename))
{
$handle = fopen($filename, 'a') or die('Cannot open file: '.$filename);
$data = " " . $_REQUEST['filedata'];
fwrite($handle, $data . PHP_EOL);
echo "File Appended Successfully...";
}
else
{
$handle = fopen($filename, 'w') or die('Cannot open file: '.$filename);
$data = 'Welcome to Grow More Institute of Computer Application';
fwrite($handle, $data);
$data = " " . $_REQUEST['filedata'];
fwrite($handle, $data . PHP_EOL);
echo "File Successfully create a file and store Contents..";
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 
Page No. 28 
}
?>
Output:

practical-11d.php
//Open File and Read Contents
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11d1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click here to Open File<br />
<input type="submit" name="openfile" value="Open/Read File" />
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 29 
practical-11d1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exists then open the file and read the contents.
if(isset($_REQUEST['openfile']))
{
if (file_exists($filename))
{
$file = fopen($filename, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br>"; //if you want to read string contents.
//echo fgetc($file). "<br>"; //if you want to read on character at a time
}
fclose($file);
}
else
{
echo "File Does Not Exists..";
}
}
?>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 30 
practical-11e.php
//Open File and Read Contents
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11e1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Click here to Open File<br />
<input type="submit" name="openfile" value="Open/Read File" />
</body>
</html>
Output:

practical-11e1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
//Check file exists or not. if exists then open the file and read the contents.
if(isset($_REQUEST['openfile']))
{
if (file_exists($filename))
{
$filehand=fopen($filename,"r") or exit("Unable to open file!");;
$data=fread($filehand,filesize($filename));
echo "<br>" . $data;
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 31 
fclose($filehand);
}
else
{
echo "File Does Not Exists..";
}
}
?>
Output:

practical-11f.php
// Copy File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11f1.php" method="post" name="filehand">
Enter File Name Here<br />
<input type="text" name="filename" /><br />
Please enter new file name to copy file and press copy button<br />
<input type="text" name="newfilenm" /><br />
<input type="submit" name="copyfile" value="Copy File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 32 
Output:

practical-11f1.php
<?php
//Get file name from user and store it to Variable
$filename=$_REQUEST['filename'];
$newfile=$_REQUEST['newfilenm'];
//Check file exists or not. if exists then copy the file.
if(isset($_REQUEST['copyfile']))
{
if (file_exists($filename))
{
if (file_exists($newfile))
{
echo "Destination file name is already exists...";
}
else
{
//copy file
copy($filename,$newfile);
echo "File Successfully copied...";
}
}
else
{
echo "File Does Not Exists..";
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 33 
}
?>
Output:

practical-11g.php
//Delete File
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11g1.php" method="post" name="filehand">
Please enter file name to delete file.<br />
<input type="text" name="deletefilenm" /><br />
<input type="submit" name="deletefile" value="Delete File" />
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 34 
Output:

practical-11g1.php
<?php
//Check file exists or not. if exists then copy the file.
$delfile=$_REQUEST['deletefilenm'];
if(isset($_REQUEST['deletefile']))
{
if (file_exists($delfile))
{
//delete file
unlink($delfile);
if (file_exists($delfile))
{
echo "File Not Deleted";
}
else
{
echo "File Successfully Deleted...";
}
}
else
{
echo "File Does Not Exists..";
}
}
?>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 35 
Output:

practical-11h.php
//File Information
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<form action="practical-11h1.php" method="post" name="filehand">
Please enter file name to get File Information.<br />
<input type="text" name="filenminfo" /><br />
<input type="submit" name="fileinfo" value="Get File Information" />
</body>
</html>
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 36 
practical-11h1.php
<?php
//Check file exists or not. if exists then Display File Information.
$filename=$_REQUEST['filenminfo'];
if(isset($_REQUEST['fileinfo']))
{
if (file_exists($filename))
{
if (is_writable($filename))
{
echo "The file is writable". "<br>";
}
else
{
echo "The file is not writable". "<br>";
}
if (is_readable($filename))
{
echo "The file is readable". "<br>";
}
else
{
echo "The file is not readable". "<br>";
}
echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename)) . "<br>";
echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename)) . "<br>";
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)) . "<br>";
echo "File Size ($filename):" . filesize($filename) . " bytes" . "<br>";
$path = dirname(__FILE__);
echo "Full path: " . $path . "<br>";
$path_parts = pathinfo($filename);
echo $path_parts['dirname'], "<br>";
echo $path_parts['basename'], "<br>";
echo $path_parts['extension'], "<br>";
echo $path_parts['filename'], "<br>";
echo realpath($filename) . "<br>";
}
else
{
echo "File Does Not Exists..";
}
}
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 37 
?>
Output:

practical-11i.php
// View Files with Links
<htm>
<head>
<title>File Handling</title>
</head>
<body>
<p>List of Files in Working Directory:</p>
<?php
$filelist = glob("*.txt");
foreach($filelist as $files)
{
echo "=> " . "<a href='$files'>$files</a>" . "<br>";
}
?>
</body>
</html>

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 38 
Output:
 

12. Write a PHP Program to Recursive Traversals of Directory.
Practical-12.php
<?php
/*
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
*/
header('Content-Type: text/plain');

$dir = dirname(__FILE__);
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $item)
{
if ($item->isFile() || $item->isDir())
{
echo $item . PHP_EOL;
}
}
?>
Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 39 
Output:

Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670) 

Page No. 40 

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Html forms
Html formsHtml forms
Html forms
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
jQuery
jQueryjQuery
jQuery
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Js ppt
Js pptJs ppt
Js ppt
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Javascript
JavascriptJavascript
Javascript
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 

Destaque

Practical java
Practical javaPractical java
Practical java
nirmit
 
List of programs for practical file
List of programs for practical fileList of programs for practical file
List of programs for practical file
swatisinghal
 
Bca sem 5 c# practical
Bca sem 5 c# practicalBca sem 5 c# practical
Bca sem 5 c# practical
Hitesh Patel
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 

Destaque (9)

Practical java
Practical javaPractical java
Practical java
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
List of programs for practical file
List of programs for practical fileList of programs for practical file
List of programs for practical file
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Types of Error in PHP
Types of Error in PHPTypes of Error in PHP
Types of Error in PHP
 
Bca sem 5 c# practical
Bca sem 5 c# practicalBca sem 5 c# practical
Bca sem 5 c# practical
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 

Semelhante a Bca sem 6 php practicals 1to12

Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
Mouli Chandira
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
Anthony Montalbano
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 

Semelhante a Bca sem 6 php practicals 1to12 (20)

Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
 
Advance java
Advance javaAdvance java
Advance java
 
Print this
Print thisPrint this
Print this
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Ex[1].3 php db connectivity
Ex[1].3 php db connectivityEx[1].3 php db connectivity
Ex[1].3 php db connectivity
 
Lab manual asp.net
Lab manual asp.netLab manual asp.net
Lab manual asp.net
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
 
Html file
Html fileHtml file
Html file
 
Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular U
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
 
1cst
1cst1cst
1cst
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.js
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Html Hands On
Html Hands OnHtml Hands On
Html Hands On
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Bca sem 6 php practicals 1to12

  • 1. HEMCHANDRACHARYA NORTH GUJARAT UNIVERSITY, PATAN B.C.A. Semester – VI BCA-604 : Building Application Using PHP & ASP.NET Teaching Scheme (per week) Examination Scheme Teaching Scheme (per semester) INT EXT TOTAL Th. (hours) Pr. (hours) Total Hours Credit Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) Th. (marks) Pr. (marks) -- 4 40 4 -- 30 -- 70 -- 100 University Examination Duration: 3 Hours (Per Batch) (Practical List) : PHP (50%) 1. Write a PHP program to display “Hello World” Message on Screen. Practical-1.php <html> <head> <title>Practical-1</title> </head> <?php echo "<b>Hello</b> <i>World</i>"; ?> <body> </body> </html> Or Practical-1a.php <?php echo "<b>Hello</b> <i>World</i>"; ?> Output: Hello World Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 1 
  • 2. 2. Write a PHP program to display the today’s date and current time. Practical-2.php <?php print strftime('%c'); echo "<br />"; print strftime('%d/%m/%Y'); echo "<br />"; print strftime('%A, %d %B - %Y'); echo "<br />"; echo "<b>Current Day, Date and Time is:</b> " . date("D M d, Y G:i A"); ?> Output: 01/19/14 11:31:16 19/01/2014 Sunday, 19 January - 2014 Current Day, Date and Time is: Sun Jan 19, 2014 11:31 AM 3. Write a PHP program to display the Fibonacci series. Practical-3.php <?php $count = 0; $no1 = 0; $no2 = 1; $tot = 0; while($count <= 10) { echo $tot . "<br />"; $no1 = $no2; $no2 = $tot; $tot = $no1 + $no2; $count ++; } ?> Or Practical-3a.php <?php $number=10; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 2 
  • 3. $firstno=0; $secondno=1; $nextno=0; $cnt=0; echo "Fibonacci Series<br><br>"; for($cnt=0;$cnt<=$number;$cnt++) { if($cnt<=1) $nextno=$cnt; else { $nextno = $firstno + $secondno; $firstno = $secondno; $secondno = $nextno; } echo $nextno . "<br>"; } ?> or practical-3b.php <?php $number=10; $i=0; $cnt=0; echo "Fibonacci Series<br><br>"; for($cnt=0 ;$cnt<=$number;$cnt++) { echo fibonacci($i) . "<br>"; $i++; } function fibonacci($number) { if ( $number == 0 ) return 0; else if ( $number == 1 ) return 1; else return ( fibonacci($number-1) + fibonacci($number-2) ); } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 3 
  • 4. ?> Output: 0 1 1 2 3 5 8 13 21 34 55 4. Write a PHP program to calculate sum of given number. Practical-4.php <?php $val1=10; $val2=10; function sum($val1,$val2) { $total=$val1+$val2; return $total; } echo "<b>Sum using Function : </b>" . sum($val1,$val2); $sum=$val1 + $val2; echo "<br />"; echo "<b>Sum is :</b> $sum"; ?> Output: Sum using Function : 20 Sum is : 20 Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 4 
  • 5. 5. Write a PHP Program that will use the concept form. Practical-5.php <html> <head> <title>Practical-5 Form Concept</title> </head> <body> <form name="frmdemo" action="practical-5a.php" method="post" > <fieldset> <legend>Enter Your Details</legend> <table width="250px" border="2" align="center"> <tr> <td align="right">Name</td> <td><input type="text" name="txtname"></td> </tr> <tr> <td align="right">Contact No</td> <td><input type="text" name="txtcno"></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"> </td> </tr> </table> </fieldset> </form> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 5 
  • 6. Practical-5a.php <?php if(isset($_REQUEST['submit'])) { $name=$_REQUEST['txtname']; $cno=$_REQUEST['txtcno']; echo "<b>Your Name is: </b>" . $name . "<br>"; echo "<b>Contact No: </b>" . $cno; } else { echo "Go Back and Press Submit button"; } ?> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 6 
  • 7. 6. Write a PHP program to read the employee detail using form component. Practical-6.php <html> <head> <title>Practical-6 Employee Form</title> </head> <body> <form name="empfrmdemo" action="practical-6a.php" method="post" > <fieldset> <legend>Grow More Computer Science</legend> <table width="360px" border="2" align="center"> <caption><b>Enter Employee Detail...</b></caption> <tr> <td align="right">Employee Name</td> <td><input type="text" name="empname" size="30px"></td> </tr> <tr> <td align="right">Address</td> <td><textarea name="empadd" cols="23"></textarea></td> </tr> <tr> <td align="right">Department</td> <td><select name="empdept"> <option value="BCA" selected>BCA</option> <option value="PGDCA">PGDCA</option> <option value="M.Sc.(CA&IT)">MSC(CA/IT)</option> </select> </td> </tr> <tr> <td align="right">Designation</td> <td><select name="empdes"> <option selected="" value="Principal">Principal</option> <option value="Professor">Professor</option> <option value="Asst.Professor">Asst.Professor</option> <option value="Lecturer">Lecturer</option> <option value="Clerk">Clerk</option> </select> </td> </tr> <tr> <td align="right">Male/Female</td> <td> <input type="radio" name="gender" value="male" checked="checked">Male<br> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 7 
  • 8. <input type="radio" name="gender" value="female">Female </td> </tr> <tr> <td align="right">Favourite Subjects</td> <td> <input type="checkbox" name="favsub[]" value="Hacking" checked="checked" />Hacking<br /> <input type="checkbox" name="favsub[]" value="Photoshop" />Photoshop<br /> <input type="checkbox" name="favsub[]" value="Forensic" checked="checked"/>Forensic<br /> <input type="checkbox" name="favsub[]" value="C Language" />C Language<br /> <input type="checkbox" name="favsub[]" value="PHP" checked="checked"/>PHP </td> </tr> <tr> <td align="right">Contact No</td> <td><input type="text" name="empcno" size="30px"></td> </tr> <tr> <td align="right">E-Mail</td> <td><input type="text" name="empmail" size="30px"></td> </tr> <tr> <td align="right">Password</td> <td><input type="password" name="emppass" size="30px"></td> </tr> <tr> <td align="right">Upload Photo</td> <td><input type="file" name="empphoto" accept="image/*" size="30px"></td> </tr> <tr> <td colspan="2" align="center"> <input type="hidden" name="empid" value="101"> <input type="submit" name="submit" value="Submit"> </td> </tr> </table> </fieldset> </form> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 8 
  • 12. 7. Write a PHP program to demonstrate the use of array. Practical-7.php <?php /*Indexed Array*/ // Indexed Array using Method-1 $gm=array("BCA","PGDCA","MSCIT"); echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . "."; echo "<br>"; //Indexed Array using Method-2 $gm[0]="BCA"; $gm[1]="PGDCA"; $gm[2]="MSCIT"; echo "I like " . $gm[0] . ", " . $gm[1] . " and " . $gm[2] . "."; echo "<br>Elements in Array:"; $arrsize=count($gm); for($cnt=0;$cnt<$arrsize;$cnt++) { echo "<br>"; echo "<b>" . $gm[$cnt] . "</b>"; } echo "<br>"; /*Associative Array*/ // Associative Array using Method-1 $gm=array("d1"=>"BCA","d2"=>"PGDCA","d3"=>"MSCIT"); echo "Degree is " . $gm['d1'] ; echo "<br>"; //Associative Array using Method-2 $gm['d1']="BCA"; $gm['d2']="PGDCA"; $gm['d3']="MSCIT"; echo "Degree is " . $gm['d2'] ; echo "<br>"; foreach($gm as $x=>$x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 12 
  • 13. Output: I like BCA, PGDCA and MSCIT. I like BCA, PGDCA and MSCIT. Elements in Array: BCA PGDCA MSCIT Degree is BCA Degree is PGDCA Key=d1, Value=BCA Key=d2, Value=PGDCA Key=d3, Value=MSCIT 8. Write a PHP program to prepare student Mark sheet using Switch statement. Practical-8.php <html> <head> <title>Practical-8 Marksheet</title> </head> <body> <form name="frmdemo" action="practical-8a.php" method="post" > <fieldset> <legend align="center">Enter Your Name with Marks Detail</legend> <table width="250px" border="2" align="center"> <tr> <td align="right">Name</td> <td><input type="text" name="txtname"></td> </tr> <tr> <td align="right">Subject-1</td> <td><input type="text" name="txtsub1"></td> </tr> <tr> <td align="right">Subject-2</td> <td><input type="text" name="txtsub2"></td> </tr> <tr> <td align="right">Subject-3</td> <td><input type="text" name="txtsub3"></td> </tr> <tr> <td align="right">Subject-4</td> <td><input type="text" name="txtsub4"></td> </tr> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 13 
  • 14. <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="Submit"></td> </tr> </table> </fieldset> </form> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 14 
  • 15. Practical-8a.php <?php if(isset($_REQUEST['submit'])) { $name=$_REQUEST['txtname']; $sub1=$_REQUEST['txtsub1']; $sub2=$_REQUEST['txtsub2']; $sub3=$_REQUEST['txtsub3']; $sub4=$_REQUEST['txtsub4']; echo "<b>Your Name is: </b>" . $name . "<br>"; echo "<b>Your Marks Detail: </b> <br>"; echo "Subject-1: " . $sub1 . "<br>"; echo "Subject-2: " . $sub2 . "<br>"; echo "Subject-3: " . $sub3 . "<br>"; echo "Subject-4: " . $sub4 . "<br>"; $total=$sub1+$sub2+$sub3+$sub4; echo "Total Marks: " . $total . "<br>"; $per=$total/4; echo "Percentage: " . $per . "%<br>"; switch($per) { case $per<35: echo "Grade: F" . "<br>"; break; case $per>=35 && $per<=50: echo "Grade: D" . "<br>"; break; case $per>50 && $per<=60: echo "Grade: C" . "<br>"; break; case $per>60 && $per<=70: echo "Grade: B" . "<br>"; break; case $per>70 && $per<100: echo "Grade: A" . "<br>"; break; default: echo "Invalid.... or out of limit"; break; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 15 
  • 16. else { echo "Go Back and Press Submit button"; } ?> Output: Your Name is: Hitesh Patel Your Marks Detail: Subject-1: 40 Subject-2: 40 Subject-3: 40 Subject-4: 40 Total Marks: 160 Percentage: 40% Grade: D 9. Write a PHP program to generate the multiplication of matrix. Practical-9.php <?php $p = array(); $p[] = array(1,3,-4); $p[] = array(1,1,-2); $p[] = array(-1,-2,5); $q = array(); $q[] = array(8,3,0); $q[] = array(3,10,2); $q[] = array(0,2,6); echo "matrix 1<br/>"; echoMatrix(3, $p); echo "<br/>"; echo "matrix 2<br/>"; echoMatrix(3, $q); echo "<br/>"; $r = matrixMultiply(3, $p, $q); echo "result of matrix multiply<br/>"; echoMatrix(3, $r); function echoMatrix($N, $r) { Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 16 
  • 17. for($i=0; $i<$N; $i++) { for($j=0; $j<=$N; $j++) { if ($j==$N) { echo "<br>"; } else { echo $r[$i][$j]; } if ($j<($N-1)) { echo ", "; } } } } function matrixMultiply($N, $p, $q) { //init result $r = array(); for($i=0; $i<$N; $i++) { $t = array(); for($j=0; $j<$N; $j++) { $t[] = 0; } $r[] = $t; } //do the matrix multiply for($i=0; $i<$N; $i++) { for($j=0; $j<$N; $j++) { $t = 0; for($k=0; $k<$N; $k++) { $t += $p[$i][$k] * $q[$k][$j]; } $r[$i][$j] = $t; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 17 
  • 18. //return result return $r; } ?> Output: Practical-9a.php <html> <head> <title>Matrix Multiplication</title> </head> <body> <form name="matrix" action="practical-9b.php" method="get"> <table border="2" cellpadding="2" cellspacing="3"> <caption><b>Please Enter 3x3 Matrix</b></caption> <tr> <td rowspan="3">Matrix-A</td> <td> <input name="a11" type="text" style="width: 50px"></td> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 18 
  • 19. <td> <input name="a12" type="text" style="width: 50px"></td> <td> <input name="a13" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="a21" type="text" style="width: 50px"></td> <td> <input name="a22" type="text" style="width: 50px"></td> <td> <input name="a23" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="a31" type="text" style="width: 50px"></td> <td> <input name="a32" type="text" style="width: 50px"></td> <td> <input name="a33" type="text" style="width: 50px"></td> </tr> <tr> <td rowspan="3">Matrix-B</td> <td> <input name="b11" type="text" style="width: 50px"></td> <td> <input name="b12" type="text" style="width: 50px"></td> <td> <input name="b13" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="b21" type="text" style="width: 50px"></td> <td> <input name="b22" type="text" style="width: 50px"></td> <td> <input name="b23" type="text" style="width: 50px"></td> </tr> <tr> <td> <input name="b31" type="text" style="width: 50px"></td> <td> <input name="b32" type="text" style="width: 50px"></td> <td> <input name="b33" type="text" style="width: 50px"></td> </tr> <tr> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 19 
  • 20. <td align="center" colspan="4"> <input name="Submit" type="submit" value="submit"></td> </tr> </table> </form> </body> </html> Output Practical-9b.php <?php if(isset($_REQUEST['submit'])) { $a = array(); $a[] = array($_REQUEST['a11'],$_REQUEST['a12'],$_REQUEST['a13']); $a[] = array($_REQUEST['a21'],$_REQUEST['a22'],$_REQUEST['a23']); $a[] = array($_REQUEST['a31'],$_REQUEST['a32'],$_REQUEST['a33']); $b = array(); $b[] = array($_REQUEST['b11'],$_REQUEST['b12'],$_REQUEST['b13']); $b[] = array($_REQUEST['b21'],$_REQUEST['b22'],$_REQUEST['b23']); $b[] = array($_REQUEST['b31'],$_REQUEST['b32'],$_REQUEST['b33']); Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 20 
  • 21. echo "Matrix-A<br/>"; dispmatrix(3, $a); echo "<br/>"; echo "Matrix-B<br/>"; dispmatrix(3, $b); echo "<br/>"; $r = matrixMultiply(3, $a, $b); echo "Matrix Multiplication<br/>"; dispmatrix(3, $r); } else { header('location:practical-9a.php'); } function dispmatrix($N, $r) { for($i=0; $i<$N; $i++) { for($j=0; $j<=$N; $j++) { if ($j==$N) { echo "<br>"; } else { echo $r[$i][$j]; } if ($j<($N-1)) { echo ", "; } } } } function matrixMultiply($N, $a, $b) { //init result $r = array(); for($i=0; $i<$N; $i++) { $t = array(); for($j=0; $j<$N; $j++) { $t[] = 0; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 21 
  • 22. } $r[] = $t; } //do the matrix multiply for($i=0; $i<$N; $i++) { for($j=0; $j<$N; $j++) { $t = 0; for($k=0; $k<$N; $k++) { $t += $a[$i][$k] * $b[$k][$j]; } $r[$i][$j] = $t; } } //return result return $r; } ?> Output:   Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 22 
  • 23. 10. Write a PHP program to send Mail from PHP Script. Practical-10.php <?php error_reporting(0); $to = "me@localhost"; $subject = "This is subject Subject"; $message = "<b>This is HTML message.</b>"; $message .= "<h1>This is headline.</h1>"; $header = "From:abc@somedomain.com rn"; $header = "Cc:afgh@somedomain.com rn"; $header .= "MIME-Version: 1.0rn"; $header .= "Content-type: text/htmlrn"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; } else { echo "Message could not be sent..."; } ?> Output: Message sent successfully... Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 23 
  • 24. 11. Write a PHP Program for Create, Delete, and Copying file from PHP Script. practical-11a.php // Enter File Name to Check Whether it is Exists or Not <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11a1.php" method="post" name="filehand"> Enter File Name to Check Whether it is Exists or Not.<br /> <input type="text" name="filename" /><br /> <input type="submit" name="checkfile" value="Check File" /> </form> </body> </html> Output: practical-11a1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if(isset($_REQUEST['checkfile'])) { if (file_exists($filename)) { echo "The file $filename exists". "<br>"; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 24 
  • 25. } else { echo "The file $filename does not exists". "<br>"; } } ?> Output: practical-11b.php //Create Blank File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11b1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click Here to Create Blank File<br /> <input type="submit" name="createfile" value="Create File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 25 
  • 26. Output: practical-11b1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if it is not exists then create new blank file if(isset($_REQUEST['createfile'])) { if (file_exists($filename)) { echo "The file $filename exists". "<br>"; } else { $handle = fopen($filename, 'w') or die('Cannot open file: '.$filename); //Check Whether the file is created or nor. if (file_exists($filename)) { echo "The $filename file Successfully Created". "<br>"; } else { echo "Error While Creating $filename". "<br>"; } } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 26 
  • 27. Output: practical-11c.php //Create, Open File and Save Data <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11c1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Please Enter Text to save in selected file<br /> <textarea name="filedata" cols="20" rows="5"></textarea><br /> <input type="submit" name="savefile" value="Create/Save/Append File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 27 
  • 28. Output: practical-11c1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exist it append the file. if not, then create new file and store data. if(isset($_REQUEST['savefile'])) { if (file_exists($filename)) { $handle = fopen($filename, 'a') or die('Cannot open file: '.$filename); $data = " " . $_REQUEST['filedata']; fwrite($handle, $data . PHP_EOL); echo "File Appended Successfully..."; } else { $handle = fopen($filename, 'w') or die('Cannot open file: '.$filename); $data = 'Welcome to Grow More Institute of Computer Application'; fwrite($handle, $data); $data = " " . $_REQUEST['filedata']; fwrite($handle, $data . PHP_EOL); echo "File Successfully create a file and store Contents.."; } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 28 
  • 29. } ?> Output: practical-11d.php //Open File and Read Contents <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11d1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click here to Open File<br /> <input type="submit" name="openfile" value="Open/Read File" /> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 29 
  • 30. practical-11d1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exists then open the file and read the contents. if(isset($_REQUEST['openfile'])) { if (file_exists($filename)) { $file = fopen($filename, "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)) { echo fgets($file). "<br>"; //if you want to read string contents. //echo fgetc($file). "<br>"; //if you want to read on character at a time } fclose($file); } else { echo "File Does Not Exists.."; } } ?> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 30 
  • 31. practical-11e.php //Open File and Read Contents <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11e1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Click here to Open File<br /> <input type="submit" name="openfile" value="Open/Read File" /> </body> </html> Output: practical-11e1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; //Check file exists or not. if exists then open the file and read the contents. if(isset($_REQUEST['openfile'])) { if (file_exists($filename)) { $filehand=fopen($filename,"r") or exit("Unable to open file!");; $data=fread($filehand,filesize($filename)); echo "<br>" . $data; Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 31 
  • 32. fclose($filehand); } else { echo "File Does Not Exists.."; } } ?> Output: practical-11f.php // Copy File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11f1.php" method="post" name="filehand"> Enter File Name Here<br /> <input type="text" name="filename" /><br /> Please enter new file name to copy file and press copy button<br /> <input type="text" name="newfilenm" /><br /> <input type="submit" name="copyfile" value="Copy File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 32 
  • 33. Output: practical-11f1.php <?php //Get file name from user and store it to Variable $filename=$_REQUEST['filename']; $newfile=$_REQUEST['newfilenm']; //Check file exists or not. if exists then copy the file. if(isset($_REQUEST['copyfile'])) { if (file_exists($filename)) { if (file_exists($newfile)) { echo "Destination file name is already exists..."; } else { //copy file copy($filename,$newfile); echo "File Successfully copied..."; } } else { echo "File Does Not Exists.."; } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 33 
  • 34. } ?> Output: practical-11g.php //Delete File <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11g1.php" method="post" name="filehand"> Please enter file name to delete file.<br /> <input type="text" name="deletefilenm" /><br /> <input type="submit" name="deletefile" value="Delete File" /> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 34 
  • 35. Output: practical-11g1.php <?php //Check file exists or not. if exists then copy the file. $delfile=$_REQUEST['deletefilenm']; if(isset($_REQUEST['deletefile'])) { if (file_exists($delfile)) { //delete file unlink($delfile); if (file_exists($delfile)) { echo "File Not Deleted"; } else { echo "File Successfully Deleted..."; } } else { echo "File Does Not Exists.."; } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 35 
  • 36. Output: practical-11h.php //File Information <htm> <head> <title>File Handling</title> </head> <body> <form action="practical-11h1.php" method="post" name="filehand"> Please enter file name to get File Information.<br /> <input type="text" name="filenminfo" /><br /> <input type="submit" name="fileinfo" value="Get File Information" /> </body> </html> Output: Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 36 
  • 37. practical-11h1.php <?php //Check file exists or not. if exists then Display File Information. $filename=$_REQUEST['filenminfo']; if(isset($_REQUEST['fileinfo'])) { if (file_exists($filename)) { if (is_writable($filename)) { echo "The file is writable". "<br>"; } else { echo "The file is not writable". "<br>"; } if (is_readable($filename)) { echo "The file is readable". "<br>"; } else { echo "The file is not readable". "<br>"; } echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename)) . "<br>"; echo "$filename was last changed: " . date("F d Y H:i:s.", filectime($filename)) . "<br>"; echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)) . "<br>"; echo "File Size ($filename):" . filesize($filename) . " bytes" . "<br>"; $path = dirname(__FILE__); echo "Full path: " . $path . "<br>"; $path_parts = pathinfo($filename); echo $path_parts['dirname'], "<br>"; echo $path_parts['basename'], "<br>"; echo $path_parts['extension'], "<br>"; echo $path_parts['filename'], "<br>"; echo realpath($filename) . "<br>"; } else { echo "File Does Not Exists.."; } } Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 37 
  • 38. ?> Output: practical-11i.php // View Files with Links <htm> <head> <title>File Handling</title> </head> <body> <p>List of Files in Working Directory:</p> <?php $filelist = glob("*.txt"); foreach($filelist as $files) { echo "=> " . "<a href='$files'>$files</a>" . "<br>"; } ?> </body> </html> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 38 
  • 39. Output:   12. Write a PHP Program to Recursive Traversals of Directory. Practical-12.php <?php /* error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); */ header('Content-Type: text/plain'); $dir = dirname(__FILE__); foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $item) { if ($item->isFile() || $item->isDir()) { echo $item . PHP_EOL; } } ?> Created By: Hitesh Patel (Asst. Professor, Grow More BCA – 9998531670)  Page No. 39