File submission by CURL php

Asked

Viewed 259 times

0

I’m having a problem using a PHP lower than 5.5, I don’t have the function curl_file_create for me to use, even though I’m not able to send could help me ?

public function enviaArquivo($arquivo){

    $ch = curl_init('https://site.com.br/upload_direto?token=xxxxxxxxxxxxx');

    curl_setopt_array($ch, [    
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => [          
          'File' => "@/var/www/site.com.br/sistema/php/cron/".$arquivo,
          'Token'=> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        ]
    ]);

    $resposta = curl_exec($ch);
    echo $resposta;
    curl_close($ch);

}

1 answer

0


From the comments in the PHP manual, you can create the function itself curl_file_create:

if (!function_exists('curl_file_create')) {
    function curl_file_create($filename, $mimetype = '', $postname = '') {
        return "@$filename;filename="
            . ($postname ?: basename($filename))
            . ($mimetype ? ";type=$mimetype" : '');
    }
}

Source: http://php.net/manual/en/curlfile.construct.php#114539

Browser other questions tagged

You are not signed in. Login or sign up in order to post.