Skip to content

Instantly share code, notes, and snippets.

@techslides
Created October 20, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save techslides/5df05f62f2a034ee537c to your computer and use it in GitHub Desktop.
Save techslides/5df05f62f2a034ee537c 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