最近用curl上传文件,发现报错

The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead

原来是PHP5.5废弃了@这种模式,只需要把原来的:

<?php
$data = array(
    'file' => '@/PATH/TO/FILE',
    //....其他字段
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

换成

$data = array(
    'file' => new CURLFile('/PATH/TO/FILE'),
    //....其他字段
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);