Step 1: create an abstract class with abstract methods.
Step 2: Create a class which inherits the abstract class.
Step 3: Implement the abstract methods in the newly created class.
Step 4: Initialize the member variables in the constructor method.
Step 5: Get the title of the webpage in the buildHeader ( ).
Step 6: Build the body of the webpage in the buildBody ( ).
Step 7: Create an object of the class in the upload.php when the upload is successful.
Step 8: Using the object call the buildHeader() and buildBody() methods.
Step 9: Run the program in the browser.
PAGE FLOW DIAGRAM:
PHP CONSTRUCTS:
Creation of abstract class - abstract class classname{ }
Creation of abstract method - abstract public function function name();
Creating an object for a class - $object name = new class name();
Calling the class methods - $object name à method name();
SOURCE CODE:
Abstract class:
<?php
abstract class webpage
{
public $title;
public $content;
abstract public function buildheader();
abstract public function buildbody();
}
?>
Webpage class:
<?php
include("webpage.php");
class homepage extends webpage
{
public function homepage($title="home page",$content="Hello")
{
$this->title=$title;
$this->content=$content;
}
public function buildheader()
{
$output="<html><head><title>$this->title</title></head>";
echo $output;
}
public function buildbody()
{
$output="<body bgcolor=#ccccff><center><br><h2>File Uploading</h2><br><br><br><h3>$this->content</h3></center></body></html>";
echo $output;
}}
?>
Upload.php
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
include("homepage.php");
$obj=new homepage("file uploading","The file has been uploaded successfully.");
$b=$obj->buildheader();
$c=$obj->buildbody();
}
else
{
include("upload.html");
echo "<center>Sorry, there was a problem in uploading your file.</center>";
}
?>
0 comments:
Post a Comment