Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. require './init.php';
  3.  
  4. if ( isset($_POST['submitfile']) )
  5. {
  6. // Make sure there are no upload errors
  7. if ($_FILES['upfile']['error'] > 0)
  8. {
  9. die("Error uploading file...");
  10. }
  11. $token = $_SESSION['access_token'];
  12. $file_path = realpath('white magnolia.jpg');
  13.  
  14. $suffix = 'image/jpeg';
  15.  
  16. $photo_name = 'white magnolia.jpg';
  17.  
  18. $inat_id = 'White Magnolia';
  19.  
  20. $boundary = rand(10,100);
  21. $body = '';
  22. $body .= '--' . $boundary . "rn";
  23. $body .= 'Content-Disposition: form-data; name="upfile"; filename=' . basename($file_path) . ""rn";
  24. $body .= 'Content-Type: ' . $suffix . "rnrn";
  25. $body .=file_get_contents($photo_name) . "rn";
  26. $body .= '--' . $boundary . "rn";
  27. $body .= 'Content-Disposition: form-data; name="observation_photo[observation_id]"' . "rn";
  28. $body .= 'Content-Type: application/json' . "rnrn";
  29. $body .= json_encode(['observation_id' => $inat_id]) . "rn";
  30. $body .= '--' . $boundary . '--' . "rn";
  31.  
  32. $photo_payload = array('observation_photos'=>array(
  33. 'method'=>'POST',
  34. 'timeout'=>'10',
  35. 'headers'=> array(
  36. 'Authorization'=>'Bearer'.$token,
  37. 'Content-Type'=>'multipart/form-data;'
  38. ),
  39. 'body' => $body
  40. ));
  41. $payload = json_encode($photo_payload);
  42.  
  43. print_r($payload);
  44.  
  45. echo "<hr><br>";
  46. $ch = curl_init();
  47. curl_setopt($ch, CURLOPT_URL, "https://api.inaturalist.org/v1/observation_photos?access_token=".$token);
  48. //curl_setopt($ch, CURLOPT_URL, "https://api.inaturalist.org/v1/observations?access_token=".$token);
  49. curl_setopt($ch, CURLOPT_HEADER, false);
  50. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  51. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0");
  52. curl_setopt($ch, CURLOPT_POST, true);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  54. $result = curl_exec($ch);
  55. curl_close($ch);
  56.  
  57. // Print the result?
  58. print_r($result);
  59. }
  60. ?>
  61. <hr>
  62. <br>
  63. <form action="post_image_rohit_12dec.php" method="post" enctype="multipart/form-data">
  64. Select file to upload:
  65. <input type="file" name="upfile">
  66. <input type="submit" value="Upload File" name="submitfile">
  67. </form>
Add Comment
Please, Sign In to add comment