来自curl php上传的空响应

时间:2016-06-25 19:02:57

标签: php curl upload

我正在使用curl在php中构建一个多文件上传。 但是,我一直在从我发布数据的服务器返回空的响应。这些文件通过文件数组中的ajax发送到这个php脚本。我知道文件存在,并且令牌有效。但是我无法得到任何有利的回应。

 $curl_options = '';

 $curl_data = array(array());
 $curl_data[0]["post"] = array();
 $curl_data[0]["post"]["folderid"] = 1568663;
 $curl_data[0]["post"]["file"] ='@'.$_FILES['files']['tmp_name'][0];
 $curl_data[0]["post"]["filename"] =$_FILES['files']['name'][0];


function multiRequest($data, $options = array()) {
$access_token = $_POST["token"];
$headers = array("Authorization: Bearer   {$access_token}");
 $url = 'https://apiv2.webdamdb.com/uploads';

  $curly = array();

  $result = array();


  $mh = curl_multi_init();

   foreach ($data as $id => $d) {

   $curly[$id] = curl_init($url);
   curl_setopt_array($curly[$id],array(   
   CURLOPT_HTTPHEADER =>  $headers,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_HEADER => 0,
   CURLOPT_CUSTOMREQUEST => "POST",
   CURLOPT_POSTFIELDS => $d["post"]));

   if (!empty($options)) {
   curl_setopt_array($curly[$id], $options);
   }
   curl_multi_add_handle($mh, $curly[$id]);
   }

   $running = null;
   do {
   $resp = curl_multi_exec($mh, $running);

  } while($running > 0);


  // get content and remove handles
  foreach($curly as $id => $c) {
    $result[$id] = curl_multi_getcontent($c);

    curl_multi_remove_handle($mh, $c);
  }

  curl_multi_close($mh);
  print_r($data);
  print_r($curly);
  print_r($result);
  return $result;
   }

  multiRequest($curl_data,$curl_options);

0 个答案:

没有答案