Thursday 16 February 2017

Upload imge in database in Project folder Using PHP




HTML FILE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="barrensavannah.css" />
<title>Clean Pune </title>

<b><u><font size=5 face="italic" color=black width=500><marquee align=top behaviour=slide  bgcolor=orange direction=left width=750 height=25 >WELCOME TO CLEAN PUNE</marquee></font></blink></u></b>


</head>

<body onload="seaproblems()">

<script type="text/javascript">
        function seaproblems()
        {
                var xmlhttp=false;
                if(window.XMLHttpRequest)
                {
                        xmlhttp=new XMLHttpRequest();
                }
                xmlhttp.onreadystatechange=function()
                {
                        if(xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
                                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                        }
                }
                xmlhttp.open("GET","seaproblems.php");
                xmlhttp.send();
        }
</script>






    <div id="page">
        <div class="topNaviagationLink"><a href="index.html">Home</a></div>
        <div class="topNaviagationLink"><a href="problems.html">Problems</a></div>
 <div class="topNaviagationLink"><a href="listofcorporators.php">Corporators</a></div>       
<div class="topNaviagationLink"><a href="contact.html">Contact Us</a></div>
<div class="topNaviagationLink"><a href="login.html">Login</a></div>

    </div>
    <div id="mainPicture">
        <div class="picture">
            <div id="headerTitle"></div>
            <div id="headerSubtext"></div>
        </div>
    </div>
        <div class="contentBox">
        <div class="innerBox">
            <h1> Enter your problem here </h1>
          <div class="contentText">
<form action=problem.php method=post enctype="multipart/form-data">   
<table width=680 align=center frame="box">

    <tr><td width="200">   Area</td><td><select name="area">
                <option value="">Select</option>
                <option value="Shaniwar Peth">Shaniwar Peth</option>
                <option value="Rupeenagar-Talawade">Rupeenagar-Talawade </option>
                <option value="Raviwar Peth">Raviwar Peth</option>
                <option value="Chikhali">Chikhali</option>   
                <option value="Krushnanagar">Krushnanagar</option>   
                 </select></td></tr>

    <tr><td>   Description</td><td><textarea rows="5" cols="50" name="desc">
    </textarea></td></tr>

<tr><td>   Upload image:</td><td> <input type="file" name="uploadedimage" id="pic"></td></tr>
</br>

<tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td><td ><input type="submit" value="Submit" /></td></tr>
</table>
</form>

<div id="txtHint">your problem will be listed here</div>

           </div>
         
         
          <!-- Please leave this in place after all of your content - thanks :) -->
<div id="footer"><a href="http://www.aszx.net"> developed</a> by <a href="http://www.bryantsmith.com">Pooja Shelke & Reshma Shinde</a></div>
<!-- Please leave this in place after all of your content - thanks :) -->
       
       
     </div>

    </div>
       
</body>
</html>




PHP FILE

<?php
include "connect.php";

$parea=$_POST['area'];
$pdesc=$_POST['desc'];


$count=1;
$row=mysql_query("select * from problem");
while($res=mysql_fetch_array($row))
$count=$count+1;


    function GetImageExtension($imagetype)
         {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }



if (!empty($_FILES["uploadedimage"]["name"]) && !empty($parea) && !empty($pdesc))
{

        $file_name=$_FILES["uploadedimage"]["name"];
        $temp_name=$_FILES["uploadedimage"]["tmp_name"];
        $imgtype=$_FILES["uploadedimage"]["type"];
        $ext= GetImageExtension($imgtype);
        $imagename=date("d-m-Y")."-".time().$ext;
        $target_path = "images/".$imagename;


    if(move_uploaded_file($temp_name, $target_path))
    {   

            $query_upload="INSERT into problem VALUES($count,'$parea','".$target_path."','$pdesc','".date("Y-m-d")."','Not Solved')";
            //mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
        if(mysql_query($query_upload))
        {
            echo "<script type='text/javascript'>";
                echo "if(confirm('Your Problem uploaded successfully'))document.location='problems.html';else document.location='problems.html';";
                   echo "</script>";   
       
        }
        else
        {
            echo "<script type='text/javascript'>";
                echo "if(confirm('Your Problem not uploaded'))document.location='problems.html';else document.location='problems.html';";
                   echo "</script>";   
        }

    }
    else
    {

           exit("Error While uploading your problem on the server");
    }
}
else
{
            echo "<script type='text/javascript'>";
                echo "if(confirm('Something Wrong'))document.location='problems.html';else document.location='problems.html';";
                   echo "</script>";   
   
}
?>


No comments:

Post a Comment

Note: only a member of this blog may post a comment.