<?php

//This code is something you set in the APP so random people cant use it.
$ACCESSKEY="mypasswd";
//these are just in case setting headers forcing it to always expire
header('Cache-Control: no-cache, must-revalidate');

if($_GET['p']==$ACCESSKEY){
//  $data = file_get_contents('php://stdin');
  $data = file_get_contents('php://input');

  $filename = "files/".$_GET['filename'];
  if (file_put_contents($filename,$data)) {
    if (filesize($filename) != 0) {
      echo "File transfer completed.";
    } else {
      header("HTTP/1.0 400 Bad Request");
      echo "Void file.";
    }
  } else {
    header("HTTP/1.0 400 Bad Request");
    echo "File transfer fail.";
  }
} else {
  header("HTTP/1.0 400 Bad Request");
  echo "Access forbidden!";     //reports if accesskey is wrong
}

?>
