public function wixmp_upload_to_servier($meta, $attachment_id) { $source_sdk = __DIR__ . '/inc/wixmedia-php/wix/media/'; require_once $source_sdk . 'WixClient.php'; $client = new WixClient($this->get_api_key(), $this->get_secret()); $filepath = get_attached_file($attachment_id); if ($image = $client->uploadImage($filepath)) { $meta['wix'] = (array) $image->getMetadata(); // error_log('The image was successfully uploaded!'); // error_log(print_r($meta['wix'], true)); } else { // error_log('An error occurred, check your php log file for more information.'); } return $meta; }
require_once __DIR__ . '/inc/wixmedia-php/wix/media/WixClient.php'; $end_point = 'media.wixapps.net'; $api_key = "wix-a091529b-0151-4768-a83e-4cb899c90de2"; $secret = "d0f8172137974a83a27bfaf00af7da20"; $client = new WixClient($api_key, $secret); $req_base64 = $_REQUEST['base64']; if (empty($req_base64)) { die('no base64 string is provided'); } $ini_val = ini_get('upload_tmp_dir'); $upload_tmp_dir = $ini_val ? $ini_val : sys_get_temp_dir(); $base64 = explode(',', $req_base64); $file = $upload_tmp_dir . '/' . uniqid() . '.' . get_string_between($base64[0], '/', ';'); $success = file_put_contents($file, base64_decode($base64[1])); $image = $client->uploadImage($file); if (!empty($image)) { $meta = (array) $image->getMetadata(); $url = $image->fit($meta['width'], $meta['height'])->getUrl(); echo json_encode($meta + array('url' => $url)); } unlink($file); function get_string_between($string, $start, $end) { $string = ' ' . $string; $ini = strpos($string, $start); if ($ini == 0) { return ''; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini;
<?php $source_dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'wix' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR; require $source_dir . 'WixClient.php'; $api_key = 'YOUR_API_KEY'; $secret = 'YOUR_API_SECRET'; $client = new WixClient($api_key, $secret); if ($image = $client->uploadImage('test.jpg')) { echo "The image was successfully uploaded!\n"; echo $image->getId(); } else { echo "An error occurred, check your php log file for more information.\n"; echo "Trying to use stock image...\n"; $image_id = 'wixmedia-samples/images/cdf1ba9ec9554baca147db1cb6e011ec/parrot.jpg'; $image = $client->getImageById($image_id); echo $image->getId(); echo "\n"; } echo $image->canvas(400, 800, 'top', 'cccccc')->getUrl(); echo '<br>'; $image->reset(); echo $image->fill(480, 240)->getUrl(); echo '<br>'; $image->reset(); echo $image->fit(480, 240, 'Lanczos2SharpFilter')->getUrl(); echo '<br>'; $image->reset(); echo $image->crop(1900, 800, 800, 900)->getUrl(); echo '<br>'; $image->reset(); echo $image->fit(120, 120)->adjust(10, -15)->getUrl();