Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Covert the curl command into php

Tags:

php

curl

I have tried to convert the curl command from https://incarnate.github.io/curl-to-php/ URL. but they are not giving me proper php code for that. Can you please help out.

curl -i -F account_id=12345 -F authhash=BKPda_T497AX4EjBsk3ttw9OcOzk -F [email protected]  https://url/upload

I tried this code to convert into php code. but not getting proper output.

 $cmd = "curl -i -F 
                account_id=12345 -F 
                authhash=BKPda_T497AX4EjBsk3ttw9OcOzk -F 
                [email protected] 
                https://url/upload";
        exec($cmd,$result);
like image 444
Maneesh Rao Avatar asked Nov 24 '25 20:11

Maneesh Rao


1 Answers

To summarize the comments:

curl -i -F account_id=12345 -F authhash=BKPda_T497AX4EjBsk3ttw9OcOzk -F [email protected]  https://url/upload

is going to be

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://url/upload");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    array(
       'account_id' => '12345',
       'authhash' => 'BKPda_T497AX4EjBsk3ttw9OcOzk',
       'audioFile' => new CURLFile('CasioVoice.wav')));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);

$server_output = curl_exec ($ch);
curl_close ($ch);

And then you may have to fight with https, depending on the server's certification. If you need that, CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST are some options to look into, but let's hope you will not need them.

like image 78
tevemadar Avatar answered Nov 27 '25 12:11

tevemadar