【问题标题】:How to save a picture in database sent from android by base64 encoding through PHP?如何通过PHP通过base64编码将图片保存在从android发送的数据库中?
【发布时间】:2016-02-06 15:50:37
【问题描述】:

我正在做一个项目,其中一部分包括将捕获的图像发送到 服务器。我使用 000webhost 作为我的服务器。从我的 android 应用程序中,我捕获图像并通过 PHP 将其发送到服务器。请帮助我任何可用的资源/链接/代码/示例如何将图片保存在数据库中。所以我可以对其应用几个操作或查询。 为了临时检查我的应用程序,我已经加载了保存在服务器文件夹中的图片。代码如下,做这项工作:

`

     // connecting to db
    $db = new DB_CONNECT();
    error_reporting(E_ALL);
    if(isset($_POST['ImageName'])){
    $imgname = $_POST['ImageName'];
    $imsrc = base64_decode($_POST['base64']);
    $fp = fopen($imgname, 'w');
    fwrite($fp, $imsrc);
    if(fclose($fp)){
      echo "success uploading image";
      }else{
          echo "Error uploading image";
       }

     }
    ?>` 

【问题讨论】:

    标签: php android mysql base64


    【解决方案1】:

    您可以将图像路径保存在数据库中,也可以保存base64本身,因为base64是一个字符串。请注意,base64 是一个长字符串,因此在创建列以保存该信息时请记住这一点。也可以看this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-29
      相关资源
      最近更新 更多