php文件上载,并带有;文件“获取内容”;到服务器

php文件上载,并带有;文件“获取内容”;到服务器,php,http,post,Php,Http,Post,是否可以按以下相同方式将文件发送到服务器: $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', 'hea

是否可以按以下相同方式将文件发送到服务器:

$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);

谢谢

是的,但这是一个乏味的过程。如果您想发布一些内容,请使用cURL或普通的
$\u文件
方法。

是的,但这是一个繁琐的过程。如果您想发布一些内容,请使用cURL或使用普通的
$\u FILE
方法。

为什么不使用cURL而不是streams?这很容易:

$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);

你为什么不用卷曲代替流呢?这很容易:

$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);

这和Facebook有什么关系?是的,这就是它的工作原理。这是一个修辞问题,还是你在文件内容和文章内容方面遇到了问题?然后查看手册中关于它的另一个示例,您搜索过这个吗?打开文件并将其内容包含在帖子正文中,您的代码运行良好。这与Facebook有什么关系?是的,它就是这样工作的。这是一个修辞问题,还是你在文件内容和文章内容方面遇到了问题?然后查看手册中关于它的另一个示例,您搜索过这个吗?打开文件并将其内容包含在文章正文中,代码运行良好。