// min 5 fields - description, email, mobile, size, target mnachine // next 5 fields - fname, lname, postcode, town, street // next 3 fields - company name, building number, flat number //-------------------------------------------------------------------- // Try and read the data out. while (($line = fgetcsv($file)) !== false) { // Check to see if the count of columns is correct $num = count($line); if ($num != 5 && $num != 10 && $num != 11 && $num != 12 && $num != 13) { // The count is wrong for this line, reject it. $message[] = "Line {$row} rejected with {$num} columns"; $row++; continue; } // Build the data structure for the REST API call. $params = array('url' => $base_url . 'parcels', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('description' => $line[0], 'receiver' => array('email' => $line[1], 'phone' => $line[2]), 'size' => $line[3], 'tmp_id' => RestApi::generate(4, 15), 'target_machine' => $line[4])); if ($num >= 10) { $params['sender_address'] = array('first_name' => $line[5], 'last_name' => $line[6], 'post_code' => $line[7], 'town' => $line[8], 'street' => $line[9]); } if ($num >= 11) { $params['sender_address']['company_name'] = $line[10]; } if ($num >= 12) { $params['sender_address']['building_number'] = $line[11]; } if ($num == 13) { $params['sender_address']['flat_number'] = $line[12]; } //echo print_r($params) . '<br>'; $ret = new RestApi($params); $info_arr = $ret->getInfo();