【发布时间】:2016-07-22 22:05:54
【问题描述】:
我需要通过 curl 将文件上传到网站。有我的代码:
$postdata['upload'] = new \CURLFile($file, 'application/zip', 'file-'.time());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
$response = curl_exec($ch);
但我得到了这个回应
$_FILES - is empty
$_POST - array (size=1) 'upload' => array (size=3) 'name' => string '/root/server1/tmp.zip' (length=21) 'mime' => string 'application/zip' (length=15) 'postname' => string 'file-1459635355' (length=59)
为什么变量 $_FILES 是空的?
【问题讨论】: