title: Python script send image to PHP
body: <p>Good day. Can somebody help me. My task is to create an python script (client side) that send image to php (server side). </p>
  
  <p>NOTE: The python script is run in different raspberry pi, and the php server only receive the image via internet. </p>
  
  <p>Achievement: I can now send a text data from my client to server.</p>
  
  <p>Problem: My big problem is how can I send the image?</p>
  
  <p>Any comments and suggestion is very appreciated. Thank You.</p>
  
  <p>My Python Script:</p>
  
  <pre><code>import urllib2
  from urllib import urlencode 
  
  # 192.168.5.149 is the ip address of server
  url = "http://192.168.5.149/server/server.php"
  data = {'test':'OK'}
  
  encoded_data = urlencode(data)
  
  website = urllib2.urlopen(url, encoded_data)
  print website.read()
  </code></pre>
  
  <p>My PHP script:</p>
  
  <pre><code>&lt;?php
  echo $_POST['test'];
  ?&gt;
  </code></pre>
  
  <p>When I run the python script, I got "ok" as send by PHP server. That means, the connection is successful.</p>
  
  <p>EDITED</p>
  
  <p>Python client:</p>
  
  <pre><code>import requests
  url = 'http://messi-fan.org/post'
  files = {'file': open('image.png', 'rb')}
  r = requests.post(url, files=files)
  </code></pre>
  
  <p>PHP server:</p>
  
  <pre><code>&lt;?php
  $file_path = "C:\\xampp\htdocs\server\php\\";
  
  $file_path = $file_path.basename( $_FILES['file']['name']);
  ?&gt;
  </code></pre>