通过 php 脚本将 csv 文件上传到 infusionsoft api

upload csv file to infusionsoft api through php script

任务是

1) 首先从数据库生成 csv 文件(我已经完成)

2) 现在将生成和下载的 csv 文件上传到 infusionsoft api

<?php
$host="localhost";
$uname="root";
$pass="";
$database = "detail"; 

$connection=mysql_connect($host,$uname,$pass); 
$selectdb=mysql_select_db($database) or die("Database could not be selected"); 
$output = ""; 
$table = "information"; // Enter Your Table Name 
$sql = mysql_query("select * from $table");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}
$filename = "myFile.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;
exit;

?>

从这段代码生成并下载 csv 文件...现在如何在 infusionsoft 中上传 csv 文件 api.....

您应该使用 FileService API. Using the PHP SDK, you would use the uploadFile() 函数。该方法看起来像:

<?php

$fileName = 'some_csv_file.csv';
$base64Enc = base64_encode($output);

$app->uploadFile($fileName, $base64Enc);

?>