angularjs - The PHP file_exists () function does not find file created on another PHP page -


i'm trying values variables in angularjs , pass them php. i'd saving array disk , retrieving later. file written disk successfully, when try contents of file, file_exists() function shows file not exist. if remove line file_exists() is, following error message appears:

warning: file_get_contents(c:/xampp/htdocs/builder3/username_15030620687196.json): failed open stream: no such file or directory in c:\xampp\htdocs\builder3\ffunc.php on line 29 warning: unlink(c:/xampp/htdocs/builder3/username_15030620687196.json): no such file or directory in c:\xampp\htdocs\builder3\ffunc.php on line 31 

the file created successfully, not know why php informs file not exist. tried using cookies, did not work. result same.

index.php:

<?php     error_reporting(e_all);     ini_set('display_errors', 1);     include($_server["document_root"]."/builder3/ffunc.php"); ?> <html ng-app="myapp">     <head>         <meta charset="utf-8">         <meta http-equiv="x-ua-compatible" content="ie=edge">         <meta name="viewport" content="width=device-width, initial-scale=1.0">         <meta name="msapplication-tap-highlight" content="no">         <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>         <script src="/builder3/js/jstest.js"></script>     </head>     <body>           <div ng-controller="testcontroller">             <?php                 $username   = "username";                 $strdtime   = str_replace(".","",sprintf("%.4f",microtime(true)));                 $scopefile  = $_server["document_root"]."/builder3/" . $username.'_'.$strdtime.'.json';             ?>             <div id="fakediv" ng-init="savescopes('<?php echo $scopefile; ?>')">                 <?php                     $getscope = loadfiletoarray($scopefile,true);                     print_r($getscope);                 ?>             </div>         </div>     </body> </html> 

testjs.js:

'use strict'; angular.module("myapp", []); angular.module("myapp").controller("testcontroller",  ["$http", "$scope", function testcontroller ($http, $scope){     $scope.var1 = 10;     $scope.var2 = "abc";     $scope.savescopes = function (jsonfile){         var variables = {             var1: $scope.var1,             var2: $scope.var2         }         $scope.$watch("variables",function() {             $http.post("php_getval.php", {"filename" : jsonfile, "variables" : variables             }).then(function(data, status, headers, config){                 return data.data.records;             }, function(data, status, headers, config){                 console.error(data);             });         });     } }]); 

php_getval.php:

<?php     include($_server["document_root"]."/builder3/ffunc.php");     header("access-control-allow-origin: *");     $data           = json_decode(file_get_contents("php://input"));     $savearr        = savearraytofile($data->filename,$data->variables,true);     header("content-type: application/json; charset=utf-8");     echo json_encode(["records" => $savearr]); ?> 

ffunc.php:

<?php     function savearraytofile($namefile, $arraytosave, $overwrite=false, $make_encode=true){         if(!file_exists($namefile)){             if($make_encode){                 $arrsav = json_encode($arraytosave);             } else {                 $arrsav = $arraytosave;             }             file_put_contents($namefile,$arrsav);             return $arrsav;         } else {             if($overwrite){                 unlink($namefile);                 if($make_encode){                     $arrsav = json_encode($arraytosave);                 } else {                     $arrsav = $arraytosave;                 }                 file_put_contents($namefile,$arrsav);                 return $arrsav;             } else {                 return null;             }         }         return null;     }      function loadfiletoarray($filetoload, $deletefileifsuccess=false){         $arrret = json_decode(file_get_contents($filetoload),true);         if($deletefileifsuccess){             unlink($filetoload);         }         return $arrret;     }  ?> 

does know why happens , best way solve it?

cheers


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -