curl上传文件并获得跳转的内容


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $url = 'http://www.myheritage.cn/FP/Company/tryFaceRecognition.php';//target url
  3.  
  4. $fields['file'] = '@'.'C:\Users\lzyy\Desktop\3431821560_5e18c02221.jpg';
  5. $fields['lang'] = 'ZH';
  6. $fields['morph'] = '1';
  7. $fields['popup'] = 'PJSLVMMT';
  8. $fields['loadMethod'] = 'myFiles';
  9.  
  10. $ch = curl_init();
  11.  
  12. curl_setopt($ch, CURLOPT_URL, $url );
  13. curl_setopt($ch, CURLOPT_POST, 1 );
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
  15. //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt ($ch, CURLOPT_REFERER, "http://www.myheritage.cn/");
  17. curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);//get redirect content
  18.  
  19. curl_exec( $ch );
  20. //$rs = curl_exec($ch);
  21.  
  22. if ($error = curl_error($ch) ) {
  23. die($error);
  24. }
  25. //print_r(htmlspecialchars($rs));
  26. echo 'ok';
  27. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.