2018-08-12 10:43
浏览 88


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:

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/ | 

I did chmod 777 files to see if permissions were part of the problem, but that did not change anything.

//FILE: save.php
$post_data = $_POST['data'];
echo(' | ');
echo(' | ');
if (!empty($post_data)) {
    $dir = '/var/www/html/files/';
    echo(' | ');
    $file = uniqid().getmypid();
    $filename = $dir.$file.'.txt';
    $handle = fopen($filename, "w");
    fwrite($handle, $post_data);
    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/.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题