0

I have CURL command I need to use him in php page how I can change it. I have no idea about it. The command :

curl --request POST \
 --url 'https://api.sirv.com/v2/files/upload?filename=%2Fpath%2Fto%2Fuploaded-image.jpg' \
 --header 'authorization: Bearer BEARER_TOKEN_HERE' \
 --header 'content-type: image/jpeg'  \
 --data "@/path/to/local-file.jpg"
1
  • 1
    Might I suggest that you take some time to read the PHP documentation about cURL? Commented Dec 30, 2020 at 15:41

1 Answer 1

1

For your curl command, Please try this PHP :

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.sirv.com/v2/files/upload?filename=%2Fpath%2Fto%2Fuploaded-image.jpg');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
    'file' => '@' .realpath('/path/to/local-file.jpg')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$headers = array();
$headers[] = 'Authorization: Bearer BEARER_TOKEN_HERE';
$headers[] = 'Content-Type: image/jpeg';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
?>

Please also study the reference provided by Professor Abronsius if you have time. It's worth the effort.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.