Skip to content

Instantly share code, notes, and snippets.

@SergeyKozlov
Forked from techslides/save.php
Created May 4, 2020 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergeyKozlov/dd9f2901c7758a5ffdbd1611b284ebc8 to your computer and use it in GitHub Desktop.
Save SergeyKozlov/dd9f2901c7758a5ffdbd1611b284ebc8 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