error_reporting(E_ALL ^ E_DEPRECATED);
        // connection to database
        include 'database.php';
    ?> <?php

        if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 
            //// Temporary file name stored on the server
            $tmpName  = $_FILES['image']['tmp_name'];  
          // //  Read the file 
            $fp      = fopen($tmpName, 'r');
            $data = fread($fp, filesize($tmpName));
            $data = addslashes($data);
            $result = mysql_query("INSERT INTO mytable (name,email,imageData)VALUES ('$name','$email','$data')", $link);
                die("Database query failed: ". mysql_error());
            // Print results
           print "Thank you, your file has been uploaded.";
            print "No image selected/uploaded";

    //i'm trying to save user details with his photo int
    mysql database with blob data type. The name and email
    insert into the table but the image does not.
    Please help. Thanks in advance

Recommended Answers

All 2 Replies


the file does not get into the database or it is just corrupted? A blob type column of which size? If you are using, say BLOB, then it can store only 65kb, the query will work but a big image will return corrupted. Also it could be an issue with the max_allowed_packet, this limits the size of the data that can be sent throught a query.


Did you check if the $_FILES array gets populated? Could you share the upload form? It could be something simple, like the enctype.

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.