【发布时间】:2017-12-10 23:45:35
【问题描述】:
我通过 curl 命令将文件和参数发布到 t.php:
t.php:
<?php
print_r( $_FILES );
print_r( $_POST );
?>
文件和参数“name”需要相同的名称:
curl http://localhost/t.php -X POST -F "name=@D:\file.zip" -F "name=test"
结果是:
Array
(
[name] => Array
(
[name] => file.zip
[type] => application/octet-stream
[tmp_name] => D:\www\tmp\php653B.tmp
[error] => 0
[size] => 150
)
)
Array
(
[name] => test
)
没关系!
但是, 如何通过 php curl CURLOPT_POSTFIELDS 为文件和参数名称发布相同的名称?
//
$data = [
'name' => curl_file_create('D:\file.zip'),
//'name' => 'test', // <--- ?????????????
];
$curl = curl_init('http://localhost/t.php');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data );
$out = curl_exec($curl);
curl_close($curl);
请帮帮我
【问题讨论】: