iam using long blob to store my images and it works fine untill user upload huge image like 2000x2000. than i get erros like:

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\xampp\htdocs\login_test\upload.php on line 41

Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\xampp\htdocs\login_test\upload.php on line 41

is there a way so that if user upload really huge image it change the size so it can fit in long blob.

here is what iam doing to upload image. i have upload.php and get.php files

get.php file-------------------------------------------------------------------------------------------------------------------------------------

    <?php 
    /*Get image from database. */
    session_start();
    include("connect.php");

    $user_id = $_SESSION['user_id']; 

    $image = mysql_query("SELECT * FROM image WHERE user_id = $user_id ORDER BY image_id DESC");
    $image = mysql_fetch_assoc($image); //get access to image table
    $image = $image['image'];
    echo base64_decode($image); 
    ?>


upload.php file-----------------------------------------------------------------------------------------------------------------------------------------------
<?php
session_start();
include("connect.php");

$user = $_SESSION['username']; //get name of who is loged in
$file = isset($_FILES['fileupload']) ? $_FILES['fileupload']['tmp_name'] : false;
$upload_error = "";

//user log in
if($user)
{
    if($file)
    {
        //user get submit button
        if($_SERVER['REQUEST_METHOD'] == 'POST')
        { 
            $image_short_name =  $_POST['imagename'];
            $image_des =  $_POST['imagedes'];

            //check for error first  (no same image_short_name)
            //scussess
            //store image in $image
            $image = chunk_split(base64_encode(file_get_contents($_FILES['fileupload']['tmp_name'])));
            //store image name in $image_full_name(.jpeg)
            $image_full_name = $_FILES['fileupload']['name'];
            //store image size in $image_size
            $image_size = getimagesize($_FILES['fileupload']['tmp_name']);
            //test if its a image or file
            if($image_size == FALSE)
            {
                echo "Thats not a image";
            }
            else
            {
                //get user id and sote in user_id_db(user thats loged in select his rows)
                $queryget = mysql_query("SELECT user_id FROM user WHERE username = '$user'") or die("query didnt work");
                $row = mysql_fetch_assoc($queryget);    
                $user_id_db = $row['user_id'];

                //insert information into database
                if(!$insert = mysql_query("INSERT INTO image VALUES(NULL, '$user_id_db', '$image', '$image_full_name', '$image_short_name', '$image_des',0,0)"))
                {
                    echo "problem uploading image";
                }
                else
                {
                    /**** print last image from database ***/
                    $lastid = mysql_insert_id(); 
                    echo "Image has been upload!<br/>";
                    echo "<img src='get.php?image_id=$image[lastid]' width='100' height='100'></img>";    
                }
            }
        }
    }
    else
    {
        echo "Please select an image.";
    }
}
else
{
    die("plz log in!");
}
?>
                                   <!-- enctype for upload images-->
<form action="upload.php" method='post' enctype = 'multipart/form-data'>
    ImageName: <input class = "text" type="text" name="imagename" /><br/>
    Description<textarea name="imagedes"cols="16" rows="4"> </textarea><br/>
    <input type ="file" name="fileupload" /><br/>
    <input type="submit" name="submit" value="sumbit" /><br/>
    <a href="gallery.php">[BACK]</a>
</form>

i was thinging this

where iam getting image_size on line 42

 $image_size = getimagesize($_FILES['fileupload']['tmp_name']);

i can some how test it.

  if($image_size > )       //i dont how long blob max size
  {
      die("size if too big");             //i want to make the size smaller here not die
  }
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.