2

test.php file

<?php

    if(isset($_POST['submit']))
    {
        if(getimagesize($_FILES['image']['tmp_name'])==FALSE)
        {
            echo "Please select an image";
        }
        else
        {
            $image = addslashes($_FILES['image']['tmp_name']);
            $image = file_get_contents($image);
            $image = base64_encode($image);
            saveimage($image);
        }
    }

    function saveimage($image)
    {
        $con=mysql_connect("localhost","root","");

        mysql_select_db("food",$con);

        $query = "INSERT INTO info(image) VALUES ('$image')";
        $result = mysql_query($query,$con);

        if($result)
        {
            echo "<br> Image upload";
        }
        else
        {
            echo "<br> NOT";
        }
    }

function displayimage()
    {
        $con=mysql_connect("localhost","root","");

        mysql_select_db("food",$con);

        $query = "SELECT image from info";
        $result = mysql_query($query,$con);
        $row=mysql_fetch_array($result);
    echo '<img src="data:image/jpeg;base64,'.$row["image"].'" width="200" height="200"/>';
    }



?>

html file

<form method="post" action="test.php">

    <label>Image:</label>
    <input type="file" name="image"><br>

    <input class="btn btn-primary" type="submit" name="submit"  value="Confirm" style="height:50px; width:100px;">

    <br><br>

</form>

Now i want to display the picture. But i keep getting a blank picture instead. Is there any problem with my display code there? Thanks

/dummy//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa//dummy

4 Answers 4

5

add enctype="multipart/form-data" in your form

<form method="post" action="test.php" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

1 Comment

add enctype="multipart/form-data in form tag.
5

Your are missing enctype="multipart/form-data" in your form tag.

The enctype attribute specifies how the form data should be encoded when submitting it to the server.

Note: The enctype attribute can be used only with method="post".

Comments

2

Add enctype="multipart/form-data" to your form tag.

Comments

0

you make a POST request, you have to encode the data that forms the body of the request.

When writing client-side code,you need to use multipart/form-data if your form includes any elements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.