is it possible to send a file to a server at the same way like this:
$file = 'myfile.txt';
or
$file = file_get_contents(./myfile.txt);
...
$postdata = http_build_query( array(
'var1' => 'some content',
'var2' => $file
) );
$opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www开发者_开发技巧-form-urlencoded', 'content' => $postdata ) );
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
Thanks
Why don't you use cURL instead of streams? It's so easy:
$ch = curl_init('http://www.url.com');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'file_input' => '@/path/to/file',
));
curl_exec($ch);
Yes, but its a tedious process. If you want to post something use cURL or with the normal $_FILE
method.
精彩评论