[英]Save Image to MySQL After crop Using ajax And PHP
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. 如我所见,许多文章都提供了一种将裁剪后的图像保存到MySQL的可能方法,但是它们同时在服务器端和客户端都使用PHP,但是在移动应用程序中同时使用PHP允许客户端使用JavaScript或Jquery。 And on server side am using PHP.
在服务器端,我正在使用PHP。
HTML: 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: 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);
});
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.