doubu1970 2013-11-13 18:02
浏览 57
已采纳

PHP / MySQLi - file_get_contents()超过了Max Allowed Packet

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!

  • 写回答

1条回答 默认 最新

  • donglianer5064 2013-11-13 18:12
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度