title: Get Ajax Header Information in PHP
body: <p>I'm making an ajax function for uploading files (video or image) like this :</p>
  
  <pre><code>function upload_file(file)
       {
          //create xhr object
          xhr = new XMLHttpRequest();
  
          //initiate request
          xhr.open('post','hisoka_drop.php',true);//true for asynchronous
  
          //set headers
          xhr.setRequestHeader('Content-Type',"multipart/form-data");
          xhr.setRequestHeader('X-File-Name',file.fileName);
          xhr.setRequestHeader('X-File-Size',file.fileSize);
          xhr.setRequestHeader('X-File-Type',file.fileType);
  
          //send the file
          xhr.send(file);
  
       }
  </code></pre>
  
  <p>And in my hisoka_drop.php :</p>
  
  <pre><code>&lt;?php
      $str =file_get_contents('php://input');
      $filename = ; //How to get ajax header about file.fileName;
      $path = 'upload/'.$filename;
      file_put_contents($path,$str);
      echo $path;
      ?&gt;
  </code></pre>
  
  <p>My question is simple, how do I get the ajax header that I have set before in order to get the real filename of the file that I want to upload to server...
  Thanks in advance... :)</p>
  
  <p>NOTE:
  I have tried to list all headers in $_SERVER as shown below :</p>
  
  <pre><code>Key ==&gt;MIBDIRS
   Value ==&gt;C:/xampp/php/extras/mibs
   Key ==&gt;MYSQL_HOME
   Value ==&gt;\xampp\mysql\bin
   Key ==&gt;OPENSSL_CONF
   Value ==&gt;C:/xampp/apache/bin/openssl.cnf
   Key ==&gt;PHP_PEAR_SYSCONF_DIR
   Value ==&gt;\xampp\php
   Key ==&gt;PHPRC
   Value ==&gt;\xampp\php
   Key ==&gt;TMP
   Value ==&gt;\xampp\tmp
   Key ==&gt;HTTP_HOST
   Value ==&gt;localhost:8080
   Key ==&gt;HTTP_CONNECTION
   Value ==&gt;keep-alive
   Key ==&gt;CONTENT_LENGTH
   Value ==&gt;305658
   Key ==&gt;HTTP_ORIGIN
   Value ==&gt;http://localhost:8080
   Key ==&gt;HTTP_USER_AGENT
   Value ==&gt;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36
   Key ==&gt;CONTENT_TYPE
   Value ==&gt;multipart/form-data
   Key ==&gt;HTTP_ACCEPT
   Value ==&gt;*/*
   Key ==&gt;HTTP_DNT
   Value ==&gt;1
   Key ==&gt;HTTP_REFERER
   Value ==&gt;http://localhost:8080/task3/
   Key ==&gt;HTTP_ACCEPT_ENCODING
   Value ==&gt;gzip, deflate
   Key ==&gt;HTTP_ACCEPT_LANGUAGE
   Value ==&gt;en-US,en;q=0.8,id;q=0.6
   Key ==&gt;HTTP_COOKIE
   Value ==&gt;PHPSESSID=crk3e9v9m4ri6k2nn8snhihu67
   Key ==&gt;PATH
   Value ==&gt;C:\Python33\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\nodejs\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;
   Key ==&gt;SystemRoot
   Value ==&gt;C:\Windows
   Key ==&gt;COMSPEC
   Value ==&gt;C:\Windows\system32\cmd.exe
   Key ==&gt;PATHEXT
   Value ==&gt;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
   Key ==&gt;WINDIR
   Value ==&gt;C:\Windows
   Key ==&gt;SERVER_SIGNATURE
   Value ==&gt;&lt;address&gt;Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.5.24 Server at localhost Port 8080&lt;/address&gt;
  
   Key ==&gt;SERVER_SOFTWARE
   Value ==&gt;Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.5.24
   Key ==&gt;SERVER_NAME
   Value ==&gt;localhost
   Key ==&gt;SERVER_ADDR
   Value ==&gt;::1
   Key ==&gt;SERVER_PORT
   Value ==&gt;8080
   Key ==&gt;REMOTE_ADDR
   Value ==&gt;::1
   Key ==&gt;DOCUMENT_ROOT
   Value ==&gt;C:/xampp/htdocs
   Key ==&gt;REQUEST_SCHEME
   Value ==&gt;http
   Key ==&gt;CONTEXT_PREFIX
   Value ==&gt;
   Key ==&gt;CONTEXT_DOCUMENT_ROOT
   Value ==&gt;C:/xampp/htdocs
   Key ==&gt;SERVER_ADMIN
   Value ==&gt;postmaster@localhost
   Key ==&gt;SCRIPT_FILENAME
   Value ==&gt;C:/xampp/htdocs/task3/hisoka_drop.php
   Key ==&gt;REMOTE_PORT
   Value ==&gt;60706
   Key ==&gt;GATEWAY_INTERFACE
   Value ==&gt;CGI/1.1
   Key ==&gt;SERVER_PROTOCOL
   Value ==&gt;HTTP/1.1
   Key ==&gt;REQUEST_METHOD
   Value ==&gt;POST
   Key ==&gt;QUERY_STRING
   Value ==&gt;
   Key ==&gt;REQUEST_URI
   Value ==&gt;/task3/hisoka_drop.php
   Key ==&gt;SCRIPT_NAME
   Value ==&gt;/task3/hisoka_drop.php
   Key ==&gt;PHP_SELF
   Value ==&gt;/task3/hisoka_drop.php
   Key ==&gt;REQUEST_TIME_FLOAT
   Value ==&gt;1469489572.122
   Key ==&gt;REQUEST_TIME
   Value ==&gt;1469489572
   Key ==&gt;REQUEST_TIME
  </code></pre>
  
  <p>And from this list, I couldn't find any header that I have sent, like FILE_NAME, FILE_SIZE, and FILE_TYPE, so what's is the problem here...??
  Thanks in advance again..</p>