<?php
//curl -X POST -F "file=@/tmp/tux.png" "http://localhost/upload.php"

$valid_file = true;
//if they DID upload a file...
if($_FILES['file']['name'])
{
  //if no errors...
  if(!$_FILES['file']['error'])
  {
    //now is the time to modify the future file name and validate the file
    //$new_file_name = strtolower($_FILES['file']['tmp_name']); //rename file
    if($_FILES['file']['size'] > (1024000)) //can't be larger than 1 MB
    {
      $valid_file = false;
      $message = 'Oops!  Your file\'s size is to large.';
    }
    
    //if the file has passed the test
    if($valid_file)
    {
      $name = basename($_FILES['file']['name']);
      //move it to where we want it to be
      //move_uploaded_file($_FILES['file']['tmp_name'], './uploads/'.basename($new_file_name));
      move_uploaded_file($_FILES['file']['tmp_name'], './uploads/'.$name);
      $message = 'Congratulations!  Your file was accepted.';
    }
  }
  //if there is an error...
  else
  {
    //set that to be the returned message
    $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['file']['error'];
  }
}

echo $message;
?>