Using PHP Curl to upload a file to resmush.it API -


i'm building automated click & optimize file uploader simple utility i'm building, , want use resmush.it api optimize uploaded images.

the upload part works fine, i'm struggling "resmush" part. code i'm using:

<?php // $file complete path uploaded file function resmush($file) {     $header = ['content-type: multipart/form-data'];      $curlcall = curl_init("http://api.resmush.it/ws.php?qlty=90");     curl_setopt($curlcall, curlopt_httpheader, $header);     curl_setopt($curlcall, curlopt_returntransfer, 1);     curl_setopt($curlcall, curlopt_post, 1);     curl_setopt($curlcall, curlopt_postfields, [         'files' => curl_file_create($file)     ]);     $result = curl_exec($curlcall);     $result = json_decode($result);     curl_close($curlcall);      print_r($result); } 

now, file loaded resmush.it $result array contains 401 error instead of optimized image path.

stdclass object (     [src] => http://static0.resmush.it/output/f8b0506cb2c33fd250cd7554af60b361/compare_2_original.jpg     [host] => static0.resmush.it     [filename] => compare_2_original.jpg     [token] => 439466ec87fc37bff74ebc3d87cca407     [error] => 401     [error_long] => cannot copy remote url     [generator] => resmush.it rev.1.4.22.20170224     [remote_server] => static2.resmush.it ) 

i have no clue i'm doing wrong...


Comments