Sending a File from a Python script to a PHP Script using POST deployed on Xampp Server -
i trying send file (may txt, pdf, xls or docx) python script php script. deployed on xampp server. far have tried several methods, no luck. python script im using send file:
url = 'http://192.168.1.8:80/testfile.php' files = {'file': open('expected.txt', 'rb')} r= requests.post(url, files=files) i have tried urllib:
f=open(filename, 'rb') filebody = f.read() f.close() data = {'name':'file','file': filebody} u = urllib.urlopen(url,urllib.urlencode(data)) print u.read(). both giving same error
undefined index: filetoupload in c:\xampp\htdocs\testfile.php on line 16
this php code posted on other end receive file python script
$target_dir = "uploads/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) {     $check = getimagesize($_files["filetoupload"]["tmp_name"]);     if($check !== false) {         echo "file image - " . $check["mime"] . ".";         $uploadok = 1;     } else {         echo "file not image.";         $uploadok = 0;     } }  
 
  
Comments
Post a Comment