Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require './init.php';
- if ( isset($_POST['submitfile']) )
- {
- // Make sure there are no upload errors
- if ($_FILES['upfile']['error'] > 0)
- {
- die("Error uploading file...");
- }
- $token = $_SESSION['access_token'];
- $file_path = realpath('white magnolia.jpg');
- $suffix = 'image/jpeg';
- $photo_name = 'white magnolia.jpg';
- $inat_id = 'White Magnolia';
- $boundary = rand(10,100);
- $body = '';
- $body .= '--' . $boundary . "rn";
- $body .= 'Content-Disposition: form-data; name="upfile"; filename=' . basename($file_path) . ""rn";
- $body .= 'Content-Type: ' . $suffix . "rnrn";
- $body .=file_get_contents($photo_name) . "rn";
- $body .= '--' . $boundary . "rn";
- $body .= 'Content-Disposition: form-data; name="observation_photo[observation_id]"' . "rn";
- $body .= 'Content-Type: application/json' . "rnrn";
- $body .= json_encode(['observation_id' => $inat_id]) . "rn";
- $body .= '--' . $boundary . '--' . "rn";
- $photo_payload = array('observation_photos'=>array(
- 'method'=>'POST',
- 'timeout'=>'10',
- 'headers'=> array(
- 'Authorization'=>'Bearer'.$token,
- 'Content-Type'=>'multipart/form-data;'
- ),
- 'body' => $body
- ));
- $payload = json_encode($photo_payload);
- print_r($payload);
- echo "<hr><br>";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://api.inaturalist.org/v1/observation_photos?access_token=".$token);
- //curl_setopt($ch, CURLOPT_URL, "https://api.inaturalist.org/v1/observations?access_token=".$token);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0");
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
- $result = curl_exec($ch);
- curl_close($ch);
- // Print the result?
- print_r($result);
- }
- ?>
- <hr>
- <br>
- <form action="post_image_rohit_12dec.php" method="post" enctype="multipart/form-data">
- Select file to upload:
- <input type="file" name="upfile">
- <input type="submit" value="Upload File" name="submitfile">
- </form>
Add Comment
Please, Sign In to add comment