0

I am trying to upload a file as a Blob from a form into a MySQL database. The problem is that max_allowed_packet is 65536 bytes and if a file is over that size it gets corrupted.

Right now I am doing this to get the file contents, which works:

$certificateWaiverFile = file_get_contents($_FILES['inputCertificateWaiverFile']['tmp_name']);

Then I use send_long_data() to insert it into the db:

$stmt->send_long_data(28, $certificateWaiverFile);

Once it gets to the DB though, it says the blob is 65536 bytes even though it's really 360KB. When I try to download it, it shows up mysteriously as 352KB instead of 65536 bytes.

Any ideas on how I can break up the file to actually get it stored in the DB correctly, assuming I can't adjust max_allowed_packet? Thanks!

Nick Tiberi
  • 1,132
  • 12
  • 20
  • 1
    This might be helpful: http://stackoverflow.com/questions/3754238/is-there-any-way-to-insert-a-large-value-in-a-mysql-db-without-changing-max-allo – showdev Nov 13 '13 at 18:05
  • 1
    Can you not adjust max_allowed_packet? If you can, this could help: http://stackoverflow.com/questions/8062496/how-to-change-max-allowed-packet-size - Otherwise showdev's answer looks great. – Bill Turner Nov 13 '13 at 18:06

1 Answers1

1

I figured out the issue. I was using BLOB instead of MEDIUMBLOB which changes the limit from 64kb to 16mb. Now I know!

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Nick Tiberi
  • 1,132
  • 12
  • 20