Skip to Content
0

Updating a .txt file with php

Nov 28, 2016 at 08:29 AM

46

avatar image

Hello community,

I want to create an app with the HANA WebIDE that read/write some data to an .txt file.

After reading that some people run php scripts with SAPUI5 I test this, but in my case it doesn´t work.

I hope somebody find my mistake and have a suitable solution, because other community discussions aren´t so helpful.

First the php file (writeFile.php) :

<?php
function phpAlert($msg) {
    $content= "123456789";
    
    $handle = fopen ("testWrite.txt", w);
    fwrite ($handle, $content);
    fclose ($handle);
    
}
?>

Secondly the call from Javascript:

writeStringToFile: function(newContent){		   
		    
     $.ajax({
	url: "writeFile.php",
        type: "GET",
        data: newContent,
	async: true,
	success: function(data){
	    console.log("Success");
	}
      });
}

Thanks in advance!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Ulrich Block
Nov 28, 2016 at 08:45 AM
0

Besides you should add input validation, an active debugger might help giving you pointers:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);

Depending of the webservers configuration required PHP functions might be disabled or other permissions are not configured properly.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Unfortunately I have no knowledge about php, so that I don´t know what should happen when your code runs. I integrate it in the script, but in the console of Chrome was nothing displayed except the console.log statement

0