0

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

2
Contributors
5
Replies
28
Views
4 Years
Discussion Span
Last Post by Raju_3
0

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

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

^^Check the validity of the above condition.

0

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

Edited by Raju_3

0

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.

1

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.