PHP: DYNAMIC WEBPAGE GENERATION USING OOPS CONCEPT
Step1: Create an abstract class with abstract class with abstract methods.
Step2: Create a class which extends the abstract class.
Step3: Implement the abstract method in the class.
Step4: Initialize the member variables in the construct method.
Step5: Get the title of the webpage in the buildHeader().
Step6: Build the body of the page in the buildBody().
Step7: Create an object of the class in the upload.php. If the upload fails and call the class
methods.
methods.
Step8: Run the program in the browser.
PROGRAM
Upload.html
<html>
<body bgcolor=violet><br><br><br><br>
<center>
<form action="upload1.php" method="post"
enctype="multipart/form-data">
<h3><label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br /><br><br>
<input type="submit" name="submit" value="Submit" /></h3>
</form>
<center>
</body>
</html>
Upload1.php
<html>
<body bgcolor=violet><br><br>
<center><h3><font color=green>DETAILS OF UPLOADED FILE</font><br><br>
<font color="maroon">
<h3><br><br><br>
<?php
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
include("homepage.php");
$obj=new homepage("file uploading","File has been uploaded successfully");
$obj->buildheader();
$obj->buildbody();
}
?>
</h3></body></html>
Homepage.php
<?php
include("webpage.php");
class homepage extends webpage
{
public function homepage($title="hello",$content="home")
{
$this->title=$title;
$this->content=$content;
}
public function buildheader()
{
$output="<html><head><title>$this->title</title></head>";
echo $output;
}
public function buildbody()
{
$output="<body><h3>$this->content</h3></body>";
echo $output;
}
}
?>
Webpage.php
<?php
abstract class webpage
{
public $title;
public $content;
abstract public function buildheader();
abstract public function buildbody();
}
?>
0 comments:
Post a Comment