File upload by CURL php

0

I have a problem I'm using a PHP under 5.5, so I do not have the curl_file_create function to use, even though I'm not able to send could you 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);

}
    
asked by anonymous 24.08.2018 / 15:55

1 answer

0

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

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

Source: link

    
24.08.2018 / 16:19