PHP - 从本地目录上传attacment

时间:2016-07-09 13:48:10

标签: php curl jira attachment

我正在尝试使用PHP cURL将本地目录中的附件上传到JIRA问题。

我一直在尝试我在SO上找到的所有解决方案,但我无法得到任何工作。当我尝试从 C:\ Users \ T116624 \ Downloads \ placeholder.jpg 上传文件时,我得到了响应:

  

创建formpost数据失败

我现在的代码是:

<?php

$username = 'username';
$password = 'password';

$ch = curl_init();
$header = array(
  'Content-Type: multipart/form-data',
   'X-Atlassian-Token: no-check'
);

$data = array('file'=>'@C:\Users\T116624\Downloads\placeholder.jpg;filename=placeholder.jpg');

$url = 'https://mysite.atlassian.net/rest/api/2/issue/27958/attachments';

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,  CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

$result = curl_exec($ch);
$ch_error = curl_error($ch);
print_r($result);
print_r($ch_error);

?>

当我尝试从php文件工作的服务器上传文件时。我这样做是使用$data = array('file'=>'@placeholder.jpg;filename=placeholder.jpg');代替$data = array('file'=>'@C:\Users\T116624\Downloads\placeholder.jpg;filename=placeholder.jpg');

我尝试使用$data = array("file" => "@" . basename($_FILES["fileToUpload"]["name"]) . ";filename=" . $_FILES["fileToUpload"]["tmp_name"]);CURLFile,但这也不起作用。我正在说我不是以正确的方式获取文件,因为它适用于与php文件在同一目录中的图像而不是C:上的文件。

0 个答案:

没有答案