【问题标题】:FILECurl in PHP7 can not upload file to the serverPHP7中的FILECurl无法上传文件到服务器
【发布时间】: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 是空的?

【问题讨论】:

    标签: php curl php-7


    【解决方案1】:

    你忘了 curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 2013-07-09
      • 2013-01-28
      • 2013-07-23
      • 1970-01-01
      • 2020-12-14
      • 2019-08-09
      相关资源
      最近更新 更多