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

  • <legend id='sX8za'><style id='sX8za'><dir id='sX8za'><q id='sX8za'></q></dir></style></legend>

    <tfoot id='sX8za'></tfoot>
    1. <small id='sX8za'></small><noframes id='sX8za'>

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

        mysqli 图像 blob 插入不起作用

        时间:2023-07-30

              <tbody id='a9yKF'></tbody>

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

                  <tfoot id='a9yKF'></tfoot>
                1. <legend id='a9yKF'><style id='a9yKF'><dir id='a9yKF'><q id='a9yKF'></q></dir></style></legend>
                  本文介绍了mysqli 图像 blob 插入不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将图像文件上传到我的 MySql 数据库.我已经在网上搜索过,我终于开始使用以下脚本:

                  I'm trying to upload an image file to my MySql Database. I've already seacrh on the web and I finally start using the following script:

                  if(is_uploaded_file($_FILES['filename']['tmp_name'])){
                  
                  $maxsize=$_POST['MAX_FILE_SIZE'];       
                  $size=$_FILES['filename']['size'];
                  
                  // getting the image info..
                  $imgdetails = getimagesize($_FILES['filename']['tmp_name']);
                  $mime_type = $imgdetails['mime']; 
                  
                  // checking for valid image type
                  if(($mime_type=='image/jpeg')||($mime_type=='image/gif')||($mime_type=='image/png')){
                    // checking for size again
                    if($size<$maxsize){
                      $filename=$_FILES['filename']['name'];  
                      $imgData =addslashes (file_get_contents($_FILES['filename']['tmp_name']));
                  
                           if(is_uploaded_file($_FILES['filename']['tmp_name'])){
                               debug('subida ok');
                           }else{
                               debug('fallo subida');
                           }
                  
                          //echo $imgData;
                          $imgDetail=addslashes($imgdetails[3]);
                  
                  
                          $db = new mysqli('127.0.0.1','user','pass', 'db');
                          if($db->connect_error){
                              debug('Error en la conexion : '.$db->connect_errno.
                                                         '-'.$db->connect_error);
                          }
                  
                          $stmt = $db->stmt_init();
                          $stmt->prepare("INSERT INTO `image` (`name`, `image`, `type`, `size`) VALUES (?, ?, ?, ?)");
                          if($stmt===false){ debug('Error en prepare');}
                          $rc=$stmt->bind_param('sbss', $filename, $imgData, $mime_type,$imgDetail);
                          if($rc===false){ debug('Error en bind');}
                          if($stmt->execute()==false){ debug('error ' . $stmt->error); };
                          $stmt->close();
                  
                  
                    }else{
                      debug("<font class='error'>Image to be uploaded is too large..Error uploading the image!!</font>");
                    }
                  }else{
                    debug("<font class='error'>Not a valid image file! Please upload jpeg or gif image.</font>");
                  }
                  
                  }else{          
                    switch($_FILES['filename']['error']){
                  case 0: //no error; possible file attack!
                    debug("<font class='error'>There was a problem with your upload.</font>");
                    break;
                  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
                    debug( "<font class='error'>The file you are trying to upload is too big.</font>");
                    break;
                  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
                    debug( "<font class='error'>The file you are trying to upload is too big.</font>");
                    break;
                  case 3: //uploaded file was only partially uploaded
                    debug( "<font class='error'>The file you are trying upload was only partially uploaded.</font>");
                    break;
                  case 4: //no file was uploaded
                    debug( "<font class='error'>You must select an image for upload.</font>");
                    break;
                  default: //a default error, just in case! 
                    debug( "<font class='error'>There was a problem with your upload.</font>");
                    break;
                    }     
                  }   
                  

                  上传的图像似乎在处理脚本输出中找到,但查看数据库大小为 0 字节...有人知道这是为什么吗?

                  推荐答案

                  mysqli SEND_LONG_DATA()!!!

                  mysqli SEND_LONG_DATA()!!!

                  http://php.net/manual/en/mysqli-stmt.send-long-data.php

                  对于某些 php/mysql(尤其是 mysqli 库)服务器设置,Blob 似乎特别令人沮丧.在配置设置无法解决问题的情况下,此解决方案似乎始终有效.如果重新实施很头疼,我会建议 PDO.

                  Blobs seem to be particularly frustrating for certain php/mysql (especially with the mysqli lib) server setups. This solution seems to consistently work where config settings fail to fix the problem. If its a headache to re-implement I would suggest PDO.

                  这篇关于mysqli 图像 blob 插入不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:php mysqli WHERE IN (?,?,? ...) 下一篇:PHP 将 mysql 转换为 mysqli

                  相关文章

                  最新文章

                  <legend id='B3Qgs'><style id='B3Qgs'><dir id='B3Qgs'><q id='B3Qgs'></q></dir></style></legend>

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

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