Hello sir iam trying to upload the image in database..this is my code

<html>
<head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="image" accept="image/jpeg">
<input type="Submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit']))

//connecting to database

    $db = mysql_connect("localhost:3306","root","") or die(mysql_error());

     //selecting our database

    $db_select = mysql_select_db("tutorial",$db) or die(mysql_error());

    $imageName = mysql_real_escape_string($_FILES["image"]["name"]);
    $imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
    $imageType = mysql_real_escape_string(($_FILES["image"]["type"]));

    if(substr($imageType,0,5) == "image")
    {
        mysql_query("insert into blob values('','$imageName','$imageData')");

        echo "image upload";
        }
        else
        {
         echo "only images are allowed";
         }
 }
?>
</body>
</html>

when iam click the uplaod button the image upload is successfully displayed on the page..but when iam see the databse no fileds are uploaded plese help me sir

Member Avatar for iamthwee

Save image in a directory. Save path to directory in database.

if(substr($imageType,0,5) == "image")

^^Check the validity of the above condition.

tell me how to create save path to directory in my code to database. sir

Member Avatar for iamthwee

Your task requires different steps. Break it down.

  1. Figure out how to upload a file
  2. Figure out how to get the path
  3. Figure out how to store this path in the database.

That's about all there is to it. You can find plenty of examples on the internet.

i got it..just i had change the mysql_real_escape_string replace to addslashes its working

i got it..just i had change the mysql_real_escape_string replace to addslashes and change the table name blob.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.