Skip to content

Instantly share code, notes, and snippets.

@edutrul
Last active March 2, 2020 00:03
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 edutrul/b9cf47337ab628b75016db9bd96245dc to your computer and use it in GitHub Desktop.
Save edutrul/b9cf47337ab628b75016db9bd96245dc to your computer and use it in GitHub Desktop.
Convert image byte array json object to download it into a file
<?php
// https://example.com/api/v1/file?id=8972893948981
// Displays the following json object:
// {"asset":{"file":{"data":[-119,80,78,71,13,10,26,10,0,0,0,13,73,,,,, etc
// Here's the php cone snippet to display to image in the browser.
$result = json_decode(file_get_contents($full_url));
$raw_file = implode(array_map('chr', $result->asset->file->data));
$file_path = $result->asset->file->path;
file_put_contents($file_path, $raw_file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment