PHP script for file Upload
(1)step 1: write code for "slider.html"
<form action="sliderupload.php" method="post" enctype="multipart/form-data">
UPload<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
(2)step 2: write code for "sliderupload.html"
<?php
$image=$_FILES['image']['name'];
include("connect.php");
$sql="insert into slider(image)values('$image')";
mysql_query($sql) or die(mysql_errror());
move_uploaded_file($_FILES['image']['tmp_name'],"slider/".$_FILES['image']['name']) or die(mysql_error());
?>
(3)write code for class.php file :
<?php
class db
{
var $host="servername";
var $username="username";
var $password="password";
function connect()
{
$connect=mysql_connect($this->host,$this->username,$this->password);
mysql_select_db("a1390987_om",$connect) or die(mysql_error());
if(!$connect)
{
echo "connection error ";
}
}
function display($table)
{
$sql="select * from $table ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
return $row;
}
}
$obj=new db();
$obj->connect();
?>
(4)use img tag to display image & write following code for displayslider.php:
<?php
include("class.php");
$table="slider";
$slider=$obj->display($table);
$image=$slider['image'];
echo $image;
echo "<img src='slider/".$image."' height=200 width=200 border=10 >";
?>
(1)step 1: write code for "slider.html"
<form action="sliderupload.php" method="post" enctype="multipart/form-data">
UPload<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
(2)step 2: write code for "sliderupload.html"
<?php
$image=$_FILES['image']['name'];
include("connect.php");
$sql="insert into slider(image)values('$image')";
mysql_query($sql) or die(mysql_errror());
move_uploaded_file($_FILES['image']['tmp_name'],"slider/".$_FILES['image']['name']) or die(mysql_error());
?>
(3)write code for class.php file :
<?php
class db
{
var $host="servername";
var $username="username";
var $password="password";
function connect()
{
$connect=mysql_connect($this->host,$this->username,$this->password);
mysql_select_db("a1390987_om",$connect) or die(mysql_error());
if(!$connect)
{
echo "connection error ";
}
}
function display($table)
{
$sql="select * from $table ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
return $row;
}
}
$obj=new db();
$obj->connect();
?>
(4)use img tag to display image & write following code for displayslider.php:
<?php
include("class.php");
$table="slider";
$slider=$obj->display($table);
$image=$slider['image'];
echo $image;
echo "<img src='slider/".$image."' height=200 width=200 border=10 >";
?>
No comments:
Post a Comment