php - Mailchimp import campaign content from .txt -


i have following code. imports .txt file, content, want send content maichimp , insert campaign. how can it?

<?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); if ($_files["filetoupload"]["size"] > 500000) {     echo "sorry, file large.";     $uploadok = 0; } // allow file formats if($imagefiletype != "txt" ) {     echo "sorry, txt files allowed.";     $uploadok = 0; }      function formatquotes($text) {         $quotestarttag = '<em>';         $quoteendtag = '</em>';          $quotes = array('"','”');         ($i = 0; $i < count($quotes); $i++) {             $currentquote = $quotes[$i];             $textparts = explode($currentquote, $text);             ($j = 0; $j < count($textparts); $j++) {                 if (($j % 2) != 0)                 {                     $textparts[$j] = $quotestarttag . $quotes[$i] . $textparts[$j] . $quotes[$i] . $quoteendtag;                 }             }             $text = implode("", $textparts);         }        return $text;     }     function extracttext($filename) {         global $output;         static $count = 1;         $filetitle = null;         $filedate = null;         $filebibleparagraph = null;         $filereference = null;         $filecontent = null;         $empty_line_mark = "{tomlinje}";         $file = fopen($filename, 'r') or exit("unable open file! : " . $filename);     $letters = array();         while (!feof($file)) {             $row = rtrim(fgets($file));             if (!empty($row)) {                 if (strstr($row, $empty_line_mark))                     $row = "";                 if (is_null($filedate))                     $filedate = $row;                 else if (is_null($filetitle))                     $filetitle = $row;                 else if (is_null($filebibleparagraph))                     $filebibleparagraph = $row;                 else if (is_null($filereference))                     $filereference = $row;                 else if (!empty($filedate) && strtotime($row))                 {                     $letters[] = array($filetitle, $filedate, $filebibleparagraph, $filecontent, $filereference);                                $filecontent = formatquotes($filecontent);         if ((strlen($filetitle) != 0) && (strlen($filedate) != 0) && (strlen($filecontent) != 0))                     $output .= $count . ". " . $filetitle . " ->> text interpreted. <br>";             else                     exit($output . "<br><br><br><br>" . $count . ". " . $filetitle . " ->> file not interpreted, check if follows default pattern!");             $count++;                                    $filedate = $row;                     $filetitle = null;                     $filebibleparagraph = null;                     $filereference = null;                         $filecontent = null;                 }                 else {                                    $filecontent .= "<p>" . $row . "</p>";                 }             }             }         fclose($file);            return $letters;     }   // check if $uploadok set 0 error if ($uploadok == 0) {     echo "sorry, file not uploaded."; // if ok, try upload file } else {     if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) {         echo "the file ". basename( $_files["filetoupload"]["name"]). " has been uploaded.";          //$content = extracttext($target_file);           $contentarray2 = extracttext($target_file);         ($i = 0; $i < count($contentarray2); $i++)         {             $contentarray = $contentarray2[$i];             $title = $contentarray[0];             $date = $contentarray[1];             $bibleparagraph = $contentarray[2];             $content = $contentarray[3];             $reference = $contentarray[4];          }                $username = "does-not-matter";             $password = "1d2bf05160324dc9cb326ec972eeca91-us8";                  $process = curl_init();                 //curl_setopt($process, curlopt_url, "https://us8.api.mailchimp.com/3.0/campaigns");                   //curl_setopt($process, curlopt_url, "https://us8.api.mailchimp.com/3.0/campaigns/2508101/content");                   curl_setopt($process, curlopt_url, "https://us8.api.mailchimp.com/3.0/campaigns/4605a8b905/content");                   curl_setopt($process, curlopt_userpwd, $username . ":" . $password);                 curl_setopt($process, curlopt_timeout, 30);                 curl_setopt($process, curlopt_httpheader, array( "content-type: application/json" ));                 curl_setopt($process, curlopt_postfields, "{'html': 'https://us8.api.mailchimp.com/3.0/campaigns/4605a8b905/content'}");                 curl_setopt($process, curlopt_header, true);                 curl_setopt($process, curlopt_customrequest, "post");                 curl_setopt($process, curlopt_returntransfer, true);       )                                    curl_close($process);      } else {         echo "sorry, there error uploading file.";     } } ?> 

)


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -