Skip to content

Instantly share code, notes, and snippets.

@tdeck
Last active February 2, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdeck/7118c7128a4a2b653d11 to your computer and use it in GitHub Desktop.
Save tdeck/7118c7128a4a2b653d11 to your computer and use it in GitHub Desktop.
Example
<?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'
)
);
?>
@sohanacutweb
Copy link

I am getting Error:
stdClass Object
(
[type] => bad_request
[message] => Invalid multipart form data
)

@sohanacutweb
Copy link

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