我尝试使用PHP将.pdf文件从我的个人CRM上载到Hubspot根文件夹中:
generateSequence { Random.nextInt(n) }
.takeWhile(checkSet::add) // as said: for this specific condition it doesn't make sense...
.forEach { /* do nothing except consume the sequence */ } // the same values you added to the set would be available in this step of course
我得到这个错误:
<a id="linkA" href="xxx"></a>
<a id="linkB"></a>
var a = $('#linkA').attr("href");
var b = $('#linkB').attr('href', a);
console.log(b);
pdf文件与php脚本位于同一文件夹中。
我尝试了不同的路径,例如:
$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$hapikey;
$realpath = "http://localhost:8888/steps/D_201803_14122.pdf";
$headers = array("Content-Type:multipart/form-data");
$postfields = array("files"=>$realpath,'file_names'=>'D_201803_14122FROMPHP.pdf');
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
if(!curl_errno($ch)) {
$info = curl_getinfo($ch);
if ($info['http_code'] == 200)
$msg = "File uploaded successfully";
echo $msg;
} else {
$errmsg = curl_error($ch);
echo $errmsg;
}
curl_close($ch);
仍然是相同的错误
这段代码有什么问题?
谢谢。
答案 0 :(得分:0)
您可以使用curl_file_create()
将文件添加到请求中$ realpath应该是本地路径,而不是URL。类似于getcwd()。 “ /D_201803_14122.pdf如果脚本与文件位于同一目录中,则应该可以使用。
$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$hapikey;
$realpath = getcwd() . "/D_201803_14122.pdf";
$headers = array("Content-Type:multipart/form-data");
$postfields = array("files"=>curl_file_create($realpath),'file_names'=>'D_201803_14122FROMPHP.pdf');
$ch = curl_init();
...