如何使用file_get_contents发送文件?

时间:2012-12-19 15:12:16

标签: php rest file-get-contents

  

可能重复:
  Upload a file using file_get_contents

我想在file_get_contents的其他服务器中发送jpg文件?

我将此用于POST数据,但如果我将jpg文件放在data数组

中则不起作用
$postdata = http_build_query(
    array(
        'collection' => 'test',
        'data' =>  array('name'=>'Test name','Surname'=>'Test Surname')
    )
);

$opts = array(
    'http' => array(
        'method' => "POST",
        'header' => "Connection: close\r\n".
                "Content-type: application/x-www-form-urlencoded\r\n".
                "Content-Length: ".strlen($postdata)."\r\n",
        'content' => $postdata
    )
);

$context = stream_context_create($opts);

$result = file_get_contents('http://localhost/test/index.php/save-doc', false, $context);

0 个答案:

没有答案