我将使用PHP创建AngularJS数组

我将使用PHP创建AngularJS数组,php,angularjs,Php,Angularjs,我有这些数据: controller.js(angularJS) 我使用http发送这些变量来创建Json.php,其中包含数组并尝试打印所有内容。我所拥有的是: createJson.php <?php $datos = $request->datas; echo $datos; $myData = json_decode($_POST['datas']); print_r($myData); if(file_get_co

我有这些数据:

controller.js(angularJS)

我使用http发送这些变量来创建Json.php,其中包含数组并尝试打印所有内容。我所拥有的是:

createJson.php

<?php    
    $datos = $request->datas;
    echo $datos;

    $myData = json_decode($_POST['datas']);

    print_r($myData);

      if(file_get_contents("php://input")){
        $json = file_get_contents("php://input");

      $file = fopen($dir,'w+');
      fwrite($file, $email);
      fclose($file);
    }
?>

我没有返回任何内容,我生成的文件是空的。


<?php

  $dir='../less/variables.json';

if(file_exists($dir)) 
{ 
if(unlink($dir)) 
print "El archivo fue borrado"; 
} 
else 
print "Este archivo no existe"; 

$datos = $request->datas;
echo $datos;

$myData = json_decode($_POST['datas']);

print_r($myData);

  if(file_get_contents("php://input")){
    $json = file_get_contents("php://input");

  $file = fopen($dir,'w+');
  fwrite($file, $json);
  fclose($file);
}

?>

$input=file\u get\u contents(“php://input");如果(!empty($input)){…fwrite($file,$input);…}
只读取一次输入流,但要像我所能做的那样使用PHP中的数组AngularJS@cskefile为空,因为
php://input
只有当我想把你在浏览器中看到的AngularJS数组写入TXT时才能读取@cskeI了解您的目标,我想解释一下php代码失败的原因和原因,尽管
fwrite($file,$email)应该是
fwrite($file,$json)
<?php

  $dir='../less/variables.json';

if(file_exists($dir)) 
{ 
if(unlink($dir)) 
print "El archivo fue borrado"; 
} 
else 
print "Este archivo no existe"; 

$datos = $request->datas;
echo $datos;

$myData = json_decode($_POST['datas']);

print_r($myData);

  if(file_get_contents("php://input")){
    $json = file_get_contents("php://input");

  $file = fopen($dir,'w+');
  fwrite($file, $json);
  fclose($file);
}

?>