<?php
require 'src/Cloudinary.php';
require 'src/Uploader.php';
require 'src/Api.php';



function CloudUploadImage($targetimage,$link){
	echo $targetimage; die;
	pg_prepare($link,'sqldefalut','SELECT * from w_configs WHERE name=$1');
	$result4 = pg_execute($link,'sqldefalut',array('cloud_api_key'));
	$rows = pg_fetch_array($result4);
	$api_key=$rows['value'];
	//echo $api_key; die;
	
	pg_prepare($link,'sqldefalut1','SELECT * from w_configs WHERE name=$1');
	$result5 = pg_execute($link,'sqldefalut1',array('cloud_api_secret'));
	$rows1 = pg_fetch_array($result5);
	$api_secret=$rows1['value'];
	
	pg_prepare($link,'sqldefalut2','SELECT * from w_configs WHERE name=$1');
	$result6 = pg_execute($link,'sqldefalut2',array('cloud_api_name'));
	$rows2 = pg_fetch_array($result6);
	$cloud_name=$rows2['value'];
	\Cloudinary::config(array( 
	  "cloud_name" => $cloud_name,//"ordering", 
	  "api_key" => $api_key,//"286845943699458", 
	  "api_secret" => $api_secret//"gNr8jY6sCYyihc7mrcoJHq4AaAw" 
	));

	$result_cloud_image = \Cloudinary\Uploader::upload($targetimage);
	//print_r($result_cloud_image); die;
	unlink($targetimage);
print_r($result_cloud_image);
	return json_encode($result_cloud_image);
}
?>