donglunzai4288 2015-07-11 09:50
浏览 54

使用ajax和PHP裁剪后将图像保存到MySQL

Below code crops the image after chosen from the local then provides a copy.

Is there a possible way to save the cropped image to MySQL as I have seen many articles but they use PHP for both server side and client side but as am using this to a mobile app where that allows JavaScript or Jquery in client side. And on server side am using PHP.

JSfiddel

HTML:

 <body ng-app="app" ng-controller="Ctrl">
      <div>Select an image file: <input type="file" id="fileInput" /></div>
      <div class="cropArea">
        <img-crop image="myImage" result-image="myCroppedImage"></img-crop>
      </div>
      <div>Cropped Image:</div>
      <div><img ng-src="{{myCroppedImage}}" /></div>
    </body>

JS:

angular.module('app', ['ngImgCrop'])
  .controller('Ctrl', function($scope) {
    $scope.myImage='';
    $scope.myCroppedImage='';

    var handleFileSelect=function(evt) {
      var file=evt.currentTarget.files[0];
      var reader = new FileReader();
      reader.onload = function (evt) {
        $scope.$apply(function($scope){
          $scope.myImage=evt.target.result;
        });
      };
      reader.readAsDataURL(file);
    };
    angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
  });
  • 写回答

1条回答 默认 最新

  • dongyi0114 2015-09-10 06:55
    关注

    Try this.

     $data = json_decode(file_get_contents('php://input'), true);
    
     $img = str_replace('data:image/png;base64,', '', $data['img']);
    
     $img = str_replace(' ', '+', $img);
    
     $data = base64_decode($img);
    
     $file = "images/4.jpg";
    
     file_put_contents($file, $data);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么