Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLI CURL -> PHP CURL

Tags:

php

curl

How can I translate this curl command so that it works in a PHP script?

curl --request POST --data-binary '@import.xml' --header "Content-Type: application/atom+xml" --header "Content-Length: 378" "http://url.com"

this don't work:

$data = array('file'=>$filename);                    

    $headers = array(
        'Content-Type: application/atom+xml',
        'Content-Length: 378'
    );

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'httpL//url.com');
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
curl_exec($ch);
like image 349
Jocky Avatar asked Dec 11 '25 11:12

Jocky


1 Answers

Try this:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/atom+xml'
    ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'http://siteurl.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));  
curl_exec($ch);
like image 63
FMaz008 Avatar answered Dec 14 '25 00:12

FMaz008