Mailgun\Connection\RestClient::prepareFile PHP Method

prepareFile() protected method

Prepare a file for the postBody.
protected prepareFile ( string $fieldName, string | array $filePath, integer $fileIndex ) : array
$fieldName string
$filePath string | array
$fileIndex integer
return array
    protected function prepareFile($fieldName, $filePath, $fileIndex = 0)
    {
        $filename = null;
        $resource = null;
        if (is_array($filePath) && isset($filePath['fileContent'])) {
            // File from memory
            $filename = $filePath['filename'];
            $resource = fopen('php://temp', 'r+');
            fwrite($resource, $filePath['fileContent']);
            rewind($resource);
        } else {
            // Backward compatibility code
            if (is_array($filePath) && isset($filePath['filePath'])) {
                $filename = $filePath['remoteName'];
                $filePath = $filePath['filePath'];
            }
            // Remove leading @ symbol
            if (strpos($filePath, '@') === 0) {
                $filePath = substr($filePath, 1);
            }
            $resource = fopen($filePath, 'r');
        }
        // Add index for multiple file support
        $fieldName .= '[' . $fileIndex . ']';
        return ['name' => $fieldName, 'contents' => $resource, 'filename' => $filename];
    }