Last active
January 4, 2017 05:37
-
-
Save subhashdasyam/7fe1bcd8644eb74729e5caf3135b18b0 to your computer and use it in GitHub Desktop.
File Upload via PHP Curl
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 | |
# 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