//<?php
//Purchase Data
$member = $purchase->member->member_id;
//REST API URL and KEY
$communityUrl = '...';
$apiKey = '...';
//Upload File from filesystem
// REST Endpoint
$endpoint = '/downloads/files';
$curl = curl_init( $communityUrl . 'api' . $endpoint );
// File Description
$file_desc = '<p>File Description</p>';
// File name
$filename = 'test.txt';
// Path to file
$file_url = '/home/acct/public_html/' . $filename;
// Download Page Settings
$curl_post_data = array(
'category' => 1,
'author' => $member,
'title' => 'REST Downloads POST',
'description' => $file_desc,
'files' => array(
$filename => urlencode(file_get_contents($file_url))
),
'hidden' => 1,
);
// Prepare data for cURL POST
$curl_post_data = urldecode(http_build_query($curl_post_data));
// POST Data
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "{$apiKey}:",
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $curl_post_data
) );
// Get Response
$response = curl_exec( $curl );
// Get file info array
$download_file = json_decode($response);
return "action complete";
Просто через запуск задач CRON