Skip to content

Instantly share code, notes, and snippets.

@subhashdasyam
Last active January 4, 2017 05:37
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 subhashdasyam/7fe1bcd8644eb74729e5caf3135b18b0 to your computer and use it in GitHub Desktop.
Save subhashdasyam/7fe1bcd8644eb74729e5caf3135b18b0 to your computer and use it in GitHub Desktop.
File Upload via PHP Curl
<?php
# Credit to Weslly
# Based on https://bountify.co/php-curl-api-uploader
// download the zip file
file_put_contents("file_to_upload.zip", fopen("http://someurl/file_to_upload.zip", 'r'));
// set the API Token
$api_token = "APITOKEN";
// initialise the curl request
$request = curl_init("https://". $api_token ."@api.appetize.io/v1/apps");
// send a file
curl_setopt($request, CURLOPT_POST, true);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'file' => '@' . realpath('file_to_upload.zip'),
'platform'=> 'ios'
));
// output the response
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($request);
// close the session
curl_close($request);
unlink(realpath('file_to_upload.zip'));
$r = json_decode($result, true);
//{ "publicKey": "p7nww3n6ubq73r1nh9jtauqy8w", "created": "2016-02-10T17:46:14.089Z", "updated": "2016-02-10T17:46:14.089Z", "platform": "ios", "versionCode": 1 }
foreach($k,$v as $r)
$$k = $v;
// Now you can call all the Keys fro json like this
echo $publicKey; // p7nww3n6ubq73r1nh9jtauqy8w
echo $created; // 2016-02-10T17:46:14.089Z
echo $updated; // 2016-02-10T17:46:14.089Z
echo $platform; // ios
echo $versionCode; // 1
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment