【发布时间】:2016-04-01 12:44:02
【问题描述】:
我已经能够将 FormData 从 angularJS 发送到 php,但我不知道如何做相反的事情。我目前正在尝试将 $base64 变量放入我的 angularJS 中,但我对如何去做感到很困惑。官方 angularJS 中的文档对我也没有多大帮助
https://docs.angularjs.org/api/ng/service/$http
JS
$scope.MakeGray_Button = function(){
if ($scope.imageUrl) {
var MakeGray_Form = new FormData();
MakeGray_Form.append("FileName", $scope.imageUrl);
$http({
method : "POST",
url : "../opencv/MakeGray/MakeGray.php",
data : MakeGray_Form,
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).
success(function(){
// some magic code here that grabs the $base64 variable from php
})
.error(function(){});
}
else{
alert("Please upload an image");
}
}
PHP
<?php
$imgname = $_POST["FileName"];
$inputDir = "../../uploads/" . $imgname;
$outputDir = "../../processed/" . $imgname;
$MakeGray = "./makegray " . $inputDir . " " . $outputDir;
$runExec = exec($MakeGray, $out);
$type = pathinfo($outputDir, PATHINFO_EXTENSION);
$data = file_get_contents($outputDir);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo "$base64";
?>
【问题讨论】:
-
我看不出这有什么关系?我的问题与 php 后端有关。
-
@TheVillageIdiot 我真的可以在这方面使用你的帮助!