Image Handling

connection.php
-----------------------------------------------
<?php set_time_limit(9999999);

mysql_connect("localhost","root","dial@desk")or die("could not be connected :".mysql_error());

mysql_select_db("image")or die(mysql_error());

?>
-------------------------------------------------------------
image.php
-------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Image Uploading</title>
</head>

<body>
<form method="post" action="add.php" enctype="multipart/form-data">

<input type="text" name="title" />
<br />
<input type="file" name="image" />
<br />
<input type="submit" value="submit" />
</form>
</body>
</html>
---------------------------------------------------------------------------
add.php
---------------------------------------------------------------------------
<?php
    include("conn.php");
    extract($_GET);
    extract($_POST);

        $title=$title;
        $image=$_FILES['image']['name'];
        if($image!="")
        {
            $check=mysql_query("select image from upload where image='$image' ") or die("error 1". mysql_error());
            if(mysql_num_rows($check) > 0)
            {
            echo "Image Allready exits";
            exit;
            }
                else {
                $add="img/"; 
                $image=$_FILES['image']['name'];
                
                if(move_uploaded_file($_FILES['image']['tmp_name'],$add.$image))
                {
                echo "Successfully uploaded the image";
                }
                $insert_event="INSERT INTO  upload(id,title,image)VALUES ('','$title','$image')";
$sql1=mysql_query($insert_event) or die(mysql_error());
$id=mysql_insert_id();
?>
<script>location.href="image.php";</script>
<?php            
}
}
?>
------------------------------------------------------------------------------------------
database
------------------------------------------------------------------------------------------
 -- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Jan 22, 2013 at 11:08 AM
-- Server version: 5.5.28
-- PHP Version: 5.3.10-1ubuntu3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `image`
--

-- --------------------------------------------------------

--
-- Table structure for table `upload`
--

CREATE TABLE IF NOT EXISTS `upload` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(20) NOT NULL,
  `image` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `upload`
--

INSERT INTO `upload` (`id`, `title`, `image`) VALUES
(1, 'TEST', 'geenie.gif'),
(2, 'TEST1', 'bann1.jpg'),
(3, 'TEST2', 'bann2.jpg');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

------------------------------------------------------------------------------------------------------------------------

0 comments:

Post a Comment