<?php
// upload a file (to temp directory)

require("phpVars.php");
header('Content-type:text/plain');

if(!array_key_exists('thefile', $_FILES)) {
 print "NO file uploaded ";
 exit;
}

// Validate the uploaded file
if($_FILES['thefile']['size'] === 0 || empty($_FILES['thefile']['tmp_name'])) {
    print "-Error. No file was selected (or file size of selected file exceeded limit) (file chosen=" . $_FILES['thefile']['name'] ;
    exit;
} else if($_FILES['thefile']['size'] > 100000) {
    print  '-Error. Uploaded file too large: ' . $_FILES['thefile']['size'] ;
    exit;
} else if($_FILES['thefile']['error'] !== UPLOAD_ERR_OK) {    // There was a PHP error
    print "-Error. Error uploading file ";
    exit;

} else {
   $origname=$_FILES['thefile']['name'] ;
   $idate =time();

  // Move the file
   $target=$tmpdir . 'upload_' . $idate . '.tmp'  ;

   if(move_uploaded_file($_FILES['thefile']['tmp_name'],$target)) {
        print 'Ok. File ' .  $_FILES['thefile']['name'] . ' (' . $_FILES['thefile']['size'] . ' bytes)  uploaded successfully to ' . $target     ;
   } else {
       print "-Error. There was an error moving the file.";
   }
   }

?>