Skip to content

Instantly share code, notes, and snippets.

@ilhomelv
Forked from techslides/save.php
Created January 24, 2018 21:36
Show Gist options
  • Save ilhomelv/2094192957c6d3b1022fc4fec6db4718 to your computer and use it in GitHub Desktop.
Save ilhomelv/2094192957c6d3b1022fc4fec6db4718 to your computer and use it in GitHub Desktop.
Save Ajax POST data as a file with PHP
<?php
//error_reporting(E_ALL);
//var_dump($_SERVER);
$post_data = $_POST['data'];
if (!empty($post_data)) {
$dir = 'YOUR-SERVER-DIRECTORY/files';
$file = uniqid().getmypid();
$filename = $dir.$file.'.txt';
$handle = fopen($filename, "w");
fwrite($handle, $post_data);
fclose($handle);
echo $file;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment