1

So i wrote the code below

 if($_FILES!=null && $_POST!=null){

       $file = $_FILES["image"]["tmp_name"];   

    if(!isset($file)){
    echo "Please upload an image";
}else{
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));

    $image_name = addslashes($_FILES['image']['name']);
    $type=$_POST['type'];

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

    if($image_size==FALSE)
        echo "That's not an image.";
    else
    {

        if(!(mysql_query("INSERT INTO store (name,image,type) values  ('$image_name','$image','$type')")))
            echo "Problem uploading image";
        else
        {
            $lastid = mysql_insert_id();
            echo "Image uploaded. <p /> Your image: <p /> <img id='imageId' src=get.php?id=$lastid>";
        }
    }
}
}

When i try to upload images larger than ~1M script breaks.

I've google it and tried modifying my "php.ini" and i also tried changing my mysql table type to largeblob but nothing worked.

So how do i do this ?

when i add the mysql_error give me "Got a packet bigger 'max_allowed_packet' bytes"

cankemik
  • 516
  • 3
  • 6
  • 19
  • In what way does your script break? Do you get an error message? Is there something in your server logs? –  Sep 24 '13 at 21:04
  • `print_r($_FILES);`, there should be an error in there. also storing files in the db is not recommended. –  Sep 24 '13 at 21:06
  • echos "Problem uploading page" before else statement. – cankemik Sep 24 '13 at 21:06
  • Use better error reporting, echo the mysql_error (you should upgrade to mysqli on the real though..) – Sterling Archer Sep 24 '13 at 21:08
  • In that case your call to `mysql_query()` failed. Are any errors shown? – George Brighton Sep 24 '13 at 21:09
  • when i add the mysql_error give me "Got a packet bigger 'max_allowed_packet' bytes" – cankemik Sep 24 '13 at 21:11
  • `addslashes()` provides about as much defence against SQL injection as a piece of wet toilet paper does in soaking up a swimming pool. DON'T USE IT. And you don't even use addslashes on `$type`, so you might as well not even bother at all... – Marc B Sep 24 '13 at 21:11
  • i've tried mysql_real_escape_string instead of addslashes. no change – cankemik Sep 24 '13 at 21:13
  • 2
    @cankemik google your mysql error -- http://stackoverflow.com/questions/93128/mysql-error-1153-got-a-packet-bigger-than-max-allowed-packet-bytes read that – Sterling Archer Sep 24 '13 at 21:16
  • Update your my.cnf and change the value of max_allowed_packet to 50 M....then restart mysql – Hackerman Sep 24 '13 at 21:17

0 Answers0