• <small id='FCm3u'></small><noframes id='FCm3u'>

    <i id='FCm3u'><tr id='FCm3u'><dt id='FCm3u'><q id='FCm3u'><span id='FCm3u'><b id='FCm3u'><form id='FCm3u'><ins id='FCm3u'></ins><ul id='FCm3u'></ul><sub id='FCm3u'></sub></form><legend id='FCm3u'></legend><bdo id='FCm3u'><pre id='FCm3u'><center id='FCm3u'></center></pre></bdo></b><th id='FCm3u'></th></span></q></dt></tr></i><div id='FCm3u'><tfoot id='FCm3u'></tfoot><dl id='FCm3u'><fieldset id='FCm3u'></fieldset></dl></div>

      <legend id='FCm3u'><style id='FCm3u'><dir id='FCm3u'><q id='FCm3u'></q></dir></style></legend>
        <bdo id='FCm3u'></bdo><ul id='FCm3u'></ul>

      <tfoot id='FCm3u'></tfoot>

        如何使用 PHP 7 和 MySQL 将文件从 POST 插入 longblob 列?

        How can I insert file from POST into longblob column using PHP 7 and MySQL?(如何使用 PHP 7 和 MySQL 将文件从 POST 插入 longblob 列?)
        <tfoot id='Cmrpi'></tfoot>
        • <legend id='Cmrpi'><style id='Cmrpi'><dir id='Cmrpi'><q id='Cmrpi'></q></dir></style></legend>

                <small id='Cmrpi'></small><noframes id='Cmrpi'>

                  <bdo id='Cmrpi'></bdo><ul id='Cmrpi'></ul>

                  <i id='Cmrpi'><tr id='Cmrpi'><dt id='Cmrpi'><q id='Cmrpi'><span id='Cmrpi'><b id='Cmrpi'><form id='Cmrpi'><ins id='Cmrpi'></ins><ul id='Cmrpi'></ul><sub id='Cmrpi'></sub></form><legend id='Cmrpi'></legend><bdo id='Cmrpi'><pre id='Cmrpi'><center id='Cmrpi'></center></pre></bdo></b><th id='Cmrpi'></th></span></q></dt></tr></i><div id='Cmrpi'><tfoot id='Cmrpi'></tfoot><dl id='Cmrpi'><fieldset id='Cmrpi'></fieldset></dl></div>

                    <tbody id='Cmrpi'></tbody>
                  本文介绍了如何使用 PHP 7 和 MySQL 将文件从 POST 插入 longblob 列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 PHP 7 和 MariaDB 5.5.47(在 CentOS 7 上)并且以下代码成功执行,没有错误:

                  I'm using PHP 7 and MariaDB 5.5.47 (on CentOS 7) and the following code successfully executes, with no errors:

                  $id = 3;
                  $tmp_name = $_FILES['file']['tmp_name'];
                  $fp = fopen($tmp_name, 'rb');
                  
                  $statement = $db->prepare("INSERT INTO Foo (id, data) VALUES (?, ?)");
                  $statement->bindParam(1, $id);
                  $statement->bindParam(2, $fp, PDO::PARAM_LOB);
                  $statement->execute();
                  $statement->closeCursor();
                  close($fp);
                  

                  使用 MySQL WorkBench 它显示数据"列是BLOB"(与 null 相反,如果我什么都不插入).当我尝试查询数据时,它是零字节.这段代码适用于 PHP 5,但我没有找到任何原因说明它不能适用于 PHP 7.

                  Using MySQL WorkBench it shows the "data" column is "BLOB" (as opposed to null, in the event I insert nothing). When I try to query the data, it's zero bytes. This code worked with PHP 5, but I haven't found any reason why it wouldn't work with PHP 7.

                  推荐答案

                  切换到阅读内容并将其传入工作.

                  Switching to reading the content and passing that in worked.

                  $fp = fopen($tmp_name, 'rb');
                  $content = fread($fp, filesize($tmp_name));
                  // ...
                  $statement->bindParam(2, $content, PDO::PARAM_LOB, $size);
                  

                  但是,我在上传大于 20mb 的文件时遇到了内存错误:

                  However, I run into errors about memory when uploading a file that's > 20mb:

                  致命错误:允许的内存大小为 134217728 字节已用尽(试图分配 81606320 字节)在 /var/www/app/API/docs.php在线 498

                  Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 81606320 bytes) in /var/www/app/API/docs.php on line 498

                  这篇关于如何使用 PHP 7 和 MySQL 将文件从 POST 插入 longblob 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                  Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                  Doctrine 2, query inside entities(原则 2,实体内部查询)
                  Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                  Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                  Doctrine and unrefreshed relationships(教义和未更新的关系)

                          <tbody id='UxcLV'></tbody>
                        <i id='UxcLV'><tr id='UxcLV'><dt id='UxcLV'><q id='UxcLV'><span id='UxcLV'><b id='UxcLV'><form id='UxcLV'><ins id='UxcLV'></ins><ul id='UxcLV'></ul><sub id='UxcLV'></sub></form><legend id='UxcLV'></legend><bdo id='UxcLV'><pre id='UxcLV'><center id='UxcLV'></center></pre></bdo></b><th id='UxcLV'></th></span></q></dt></tr></i><div id='UxcLV'><tfoot id='UxcLV'></tfoot><dl id='UxcLV'><fieldset id='UxcLV'></fieldset></dl></div>

                      • <tfoot id='UxcLV'></tfoot>

                        <small id='UxcLV'></small><noframes id='UxcLV'>

                      • <legend id='UxcLV'><style id='UxcLV'><dir id='UxcLV'><q id='UxcLV'></q></dir></style></legend>
                          • <bdo id='UxcLV'></bdo><ul id='UxcLV'></ul>