Last active
February 2, 2018 06:20
-
-
Save tdeck/7118c7128a4a2b653d11 to your computer and use it in GitHub Desktop.
Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function uploadItemImage($url, $access_token, $image_file) { | |
$headers = ["Authorization: Bearer $access_token"]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "@$image_file;type=image/jpeg"]); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec($ch); | |
$return_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
print "POST to $url with status $return_status\n"; | |
curl_close($ch); | |
return $data ? json_decode($data) : false; | |
} | |
print_r( | |
uploadItemImage( | |
'https://connect.squareup.com/v1/me/items/ITEM_ID/image', | |
'ACCESS_TOKEN', | |
'IMAGE_FILE.jpg' | |
) | |
); | |
?> |
Please help me how i can fix this issue?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting Error:
stdClass Object
(
[type] => bad_request
[message] => Invalid multipart form data
)