Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3694

PHP: CurlFile upload with remote URL

$
0
0

From past few days I have been searching on how to upload file in PHP >=5.5 with Curl. Finally I found the new CurlFile method but cant get it work with remote URLs. Here is the code i am using:

        $access_token = 'MY_API_ACCESS_TOKEN';        $fields = array("name" => $name,"parent" => array("id" => $folder_id            )        );        $another = array('attributes' => json_encode($fields),'file' => new CurlFile($remoteUrl)        );        $header = array ("Authorization: Bearer $access_token","Content-Type: multipart/form-data"        );        $options = array(            CURLOPT_URL => $UPLOAD_URL,            CURLOPT_POST => true,            CURLOPT_POSTFIELDS => $another,            CURLOPT_HTTPHEADER => $header,            CURLOPT_RETURNTRANSFER => true,            CURLOPT_SSL_VERIFYPEER => false        );        $ch = curl_init();        curl_setopt_array($ch, $options);        $response = curl_exec($ch);        curl_close($ch);

When replacing the $remoteUrl with local file path everything works fine.

Q] Is the remote upload possible with CurlFile? If yes what am I doing wrong?


Viewing all articles
Browse latest Browse all 3694

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>