Want to read CSV file

Hello, everyone,

I’m trying to open a CSV file using a CLI. Unfortunately I can’t do that. I want to save this file somewhere else afterwards. The error message:

Warning: fopen(Private/data/codes.csv): Failed to open stream: No such file or directory in C:

    public function importCommand(): array
    {
        $result = [];
        // Read into array
        if (($handle = fopen('Private/data/codes.csv', "r")) !== FALSE) {
            while (!feof($handle)) {
                $row = fgets($handle) ;
                if(str_contains($row, 'IW-')){
                    $result[] = $row;
                }
            }
            fclose($handle);
        }

        return $result;
    }

Thank you for a support

LG mark

Use the resource stream wrapper

https://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/ResourceManagement.html#resource-stream-wrapper

exactly :wink:

file_get_contents(
    'resource://Acme.Charity/Private/data/codes.csv'
);

Thank you, it works

FYI: The category “Creating Neos & Flow” is meant for core development. I moved your topic to “Using Neos & Flow”. This also allows you to mark the issue resolved (I did this for you in this case)