I have the PHP script below, which is intended to create a file from the payload of a POST request to NGINX. The script echos the POST request contents back to the requester, but I find no new file in /www/www/html/files
, which is where data should be saved.
Here is the POST request:
http://142.93.124.54/save.php
The body of the request is data
(the key) and This is a test!
(the value). The reply to the request is
This is a test! | /var/www/html | /var/www/html/files/ |
/var/www/html/files/5b70334ddcecb19896.txt
I did chmod 777 files
to see if permissions were part of the problem, but that did not change anything.
<?php
//FILE: save.php
$post_data = $_POST['data'];
echo($post_data);
echo(' | ');
echo(__DIR__);
echo(' | ');
if (!empty($post_data)) {
$dir = '/var/www/html/files/';
echo($dir);
echo(' | ');
$file = uniqid().getmypid();
$filename = $dir.$file.'.txt';
$handle = fopen($filename, "w");
fwrite($handle, $post_data);
fclose($handle);
echo $filename ;
}
?>
NOTE: if you are testing this, you need to do a POST request, not GET.
NOTE 2: I changed the directory to /var/ww/html/file/
and confirmed that this should be correct by echoing __DIR__
. I also added a few other echo statements, e.g., one for the final filepath to which the data is written. Alas, I find nothing in var/www/html/files/
.