I need to create a file in my server and write some contents on it using php [closed]

StackOverflow https://stackoverflow.com/questions/22589131

  •  19-06-2023
  •  | 
  •  

Pregunta

I am using a cross domain request.A request has been made to php file in a server via ajax from another server.From php side Here, I need to create a file and write some contents in that file.My request is reaching perfectly.But I am not able to create a file.Please help

NOTE : ITS A CROSS DOMAIN REQUEST

<?php
$filename = "lin.txt";
$data2 = "lin IS HERE";
$newFile= fopen($filename, 'w');
chmod($newFile, 777);
fwrite($newFile, $data2);
fclose($newFile);
?>

Thanks in advance

¿Fue útil?

Solución

In am not sure what are you going to do, because you haven't told us your code. I think this will help you:

<?php
$file = 'demo.txt';
$content = "Example\n";
file_put_contents($file, $content);
?>

The file is demo.txt (it is at the same location with the PHP document.

$content is the text which will be put on your txt file.

Hope it helps!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top