Skip to Content

Updating a .txt file with php

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!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 28, 2016 at 08:45 AM

    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.

    Add comment
    10|10000 characters needed 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