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

时间:2015-02-24 09:15:26

标签: php infusionsoft

任务是

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 api中上传csv文件.....

1 个答案:

答案 0 :(得分:1)

您应该使用FileService API。使用PHP SDK,您将使用uploadFile()函数。该方法看起来像:

<?php

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

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

?>