title: python requests module post to php script
body: <p>I need to upload some .csv file into a self signed https apache server. 
  My https server is running PHP. My client is running a python script to POST files into the https server. PHP.ini has 20M for upload_file and POST_max_size directives with no extra whitespace. The file i need to upload is only 4kilobytes</p>
  
  <p><strong>my python script:</strong></p>
  
  <pre><code>import requests
  username = "user"
  password = 'password'
  myfile = "/full/path/to/myfile.csv"
  url = "https://www.mydomain.com/file_upload.php"
  
  files = {'file': open(myfile, 'rb')}
  
  r = requests.post(url, files=files, auth=(username, password), verify=False)
  print r.text
  print r.status_code
  </code></pre>
  
  <p>I receive a status code 200 but the file is not in the destination server
  I believe the error is somewhere in my file_upload.php</p>
  
  <p>$_FILES['userfile']['name'] was the name i was using when i was posting the file from a HTML form which is not the case anymore. 
  I believe i am missing something due to my lack of understanding of the $_FILES variable in PHP - <strong>How the file-id should look like when not posting from a form?</strong></p>
  
  <pre><code>&lt;?php
  
  $uploaddir = '/var/www/html/uploads/';
  $uploadfile = $uploaddir . basename($_FILES['file-id']['name']);
  
  move_uploaded_file($_FILES['file-id']['tmp_name'], $uploadfile);
  error_log(print_r($_FILES['file-id']['error']), 3, $error_log_file);
  
  ?&gt;
  </code></pre>
  
  <p><strong>my apache error.log reports the following PHP notice</strong></p>
  
  <p>[Thu Jun 05 09:35:19.120760 2014] [:error] [pid 8030] [client xxx.xxx.xxx.xxx:49207] PHP Warning:  Missing boundary in multipart/form-data POST data in Unknown on line 0</p>
  
  <p>[Thu Jun 05 09:35:19.124625 2014] [:error] [pid 8030] [client xxx.xxx.xxx.xxx:49207] PHP Notice:  Undefined index: file in /var/www/html/file_upload.php on line 8</p>
  
  <p>[Thu Jun 05 09:35:19.124673 2014] [:error] [pid 8030] [client xxx.xxx.xxx.xxx:49207] PHP Notice:  Undefined index: file in /var/www/html/file_upload.php on line 11</p>
  
  <p>[Thu Jun 05 09:35:19.124686 2014] [:error] [pid 8030] [client xxx.xxx.xxx.xxx:49207] PHP Notice:  Undefined index: file in /var/www/html/file_upload.php on line 12</p>
  
  <p><strong>Permission</strong>
  my www folder is chown -R www-data.www-data</p>