How to send a file to external api in php

Hi guys,

I want to send a file to other websites by using curl in App php, here is my code how to do it

          $files = $this->rootFolder->getUserFolder($this->userId)->getById($fileId);
           $file = array_shift($files);
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, 'http://otherside.url' );
           curl_setopt_array ( $ch, array (
                CURLOPT_POST => 1,
                CURLOPT_SAFE_UPLOAD => false,
                CURLOPT_POSTFIELDS => array (
                  'file' => $file            
                 )
             ));
            $response = curl_exec ( $ch );

I can get $file in second line, but external website cannot get the attached file, does the $file need to convert to other type for attaching in curl request? I’m not an experenced php developer, please hint me if something is wrong

thanks
Jacky Wang