0
<?php
    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);
            fclose($fp);
    }
            $name=$_POST['name'];
            $email=$_POST['email'];  
            $result = mysql_query("INSERT INTO mytable (name,email,imageData)VALUES ('$name','$email','$data')", $link);
          if(!$result)
            {
                die("Database query failed: ". mysql_error());
            }
            // Print results
     if($result==1){
           print "Thank you, your file has been uploaded.";
        }   
        else 
        {
            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
3
Contributors
2
Replies
36
Views
11 Months
Discussion Span
Last Post by AndrisP
0

Hi,

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.

See:

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

This topic has been dead for over six months. 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.