php curl API uploader
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi guys,

I would like a php file that will upload using code and the API of appetize.io

curl https://APITOKEN@api.appetize.io/v1/apps \
-F "file=@file_to_upload.zip" -F "platform=ios"

Can you convert this into php please.

The zip file is hosted on AWS so it may need to be downloaded to the localhost where the php is hosted then run the curl to upload and then remove the zip file after.

More info https://appetize.io/docs#direct-uploads

do you want to upload the file via form or you have a file path directly?
Subhash Dasyam 4 months ago
no the file is already uploaded to a URL on AWS.
davesargent 4 months ago
no the file is already uploaded to a URL on AWS. So a path is great
davesargent 4 months ago
awarded to weslly
Tags
PHP

Crowdsource coding tasks.

2 Solutions

Winning solution

This should work

<?php
// 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);
echo curl_exec($request);

// close the session
curl_close($request);

unlink(realpath('file_to_upload.zip'));
?>
great can you remove the zip after uploading please
davesargent 4 months ago
updated the code
weslly 4 months ago
you beat me to it :P
Subhash Dasyam 4 months ago
Cool thanks :)
davesargent 4 months ago
Cool thanks :) I'm testing now and I will award within the next 30 minutes
davesargent 4 months ago
Sorry to be a pain can the results should return a json file { "publicKey": "p7nww3n6ubq73r1nh9jtauqy8w", "created": "2016-02-10T17:46:14.089Z", "updated": "2016-02-10T17:46:14.089Z", "platform": "ios", "versionCode": 1 } Can you tell me where I can access this is it echo curl_exec($request); $results = echo curlexec($request); $rows = jsondecode($results,true); echo $row['publicKey']; Will this work?
davesargent 4 months ago
@weslly not trying to hijack this thread or solution, @davesargent I have added your new request in separate solution :). To display Public Key and all Keys. Do test it :)
Subhash Dasyam 4 months ago
@davesargent sorry, I didn't see the comment earlier, thank you for the award :)
weslly 4 months ago

Based on Weslly code,

++ Added decode of Json code in this php

https://gist.github.com/subhashdasyam/7fe1bcd8644eb74729e5caf3135b18b0

Hey Thanks for the input :)
davesargent 4 months ago
Thanks for Tipping me :) @davesargent
Subhash Dasyam 4 months ago
It wasn't much sorry but happy new year to you & thanks for the help :D
davesargent 4 months ago
No that's more than enough :) i am sorry i wasn't fast enough to write the solution. thanks for tipping me that's more than enough. Thanks Dave
Subhash Dasyam 4 months ago
View Timeline