PHP Curl 上传文件

PHP Curl 上传文件

5.0以后的用法

public function upload_file_to_java($furl, $url)
{
    $data = array(
        'importfile' => new CURLFile(realpath($furl))
    );
    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_USERPWD, 'joe:secret');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $return_data = curl_exec($ch);
    curl_close($ch);
    echo $return_data;
}

服务器端接收

print_r($_POST);
print_r($_FILES);

你可能感兴趣的:(PHP)